:的WebPack 2模塊未找到:錯誤:當我想用我的創造bundle.js無法解析模塊
$ ./node_modules/.bin/webpack --config webpack.config.js
我收到以下錯誤
ERROR in ./dev/js/source/scripts/components/TextInput.js Module not found: Error: Cannot resolve module 'source/scripts/components/IconButton' in /Users/sebastien/Documents/Javascript/Tests/MyApp/dev/js/source/scripts/components @ ./dev/js/source/scripts/components/TextInput.js 4:18-65
ERROR in ./dev/js/source/scripts/components/TextInput.js Module not found: Error: Cannot resolve module 'source/scripts/SDK/classNames' in /Users/sebastien/Documents/Javascript/Tests/MyApp/dev/js/source/scripts/components @ ./dev/js/source/scripts/components/TextInput.js 15:17-57
項目樹如下
/Users/sebastien/Documents/Javascript/Tests/MyApp
- webpack.config.js
- dev
- js
- index.js
- source
- scripts
- components
- TextInput.js
- IconButton.js
- SDK
- classNames.js
在TextInput.js有下面的語句
import IconButton from "source/scripts/components/IconButton";
和我webpack.config.js包含以下
var path = require('path');
var webpack = require('webpack');
module.exports = {
devServer: {
inline: true,
contentBase: './src',
port: 8080
},
devtool: 'cheap-module-eval-source-map',
entry: './dev/js/index.js',
module: {
loaders: [
{
test: /\.js$/,
loaders: ['babel'],
exclude: /node_modules/
},
{
test: /\.scss/,
loader: 'style-loader!css-loader!sass-loader'
}
]
},
output: {
path: 'src',
filename: 'js/bundle.min.js'
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin()
]
};
如何配置的WebPack添加路徑./dev/js搜索模塊?我曾嘗試過:
- modules: [path.resolve(__dirname, "./dev/js"), "node_modules"]
沒有任何成功。你能幫我嗎?
問候,
謝謝,它有幫助,但我不想更改位於目錄腳本下的.js文件的源代碼。 我不是這些* .js文件的所有者(他們由另一個團隊提供)。我只想用webpack配置解決這個問題(如果可能的話)。 – sebastien
呃,對不起,幫不了你。我認爲我提供的答案可能有效,因爲在React中工作時我遇到了完全相同的問題。我從來沒有真正使用過webpack,但是也許如果你在谷歌搜索錯誤,比如「webpack模塊找不到修復路徑」或類似的東西,或者只是等待某人給出適當的答案。 –
不要對不起。當有人回答並嘗試提供幫助時,我總是很感激。 – sebastien