這裏是我的pacjage.json:爲什麼的WebPack不能找到裝載機
{
"name": "redux-todo",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "webpack-dev-server"
},
"devDependencies": {
"babel": "^6.5.2",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.13.2",
"babel-preset-react": "^6.11.1",
"webpack": "^1.13.2"
},
"dependencies": {
"react": "^15.3.1",
"react-dom": "^15.3.1",
"react-redux": "^4.4.5",
"redux": "^3.5.2"
}
}
webpack.config.js:
var path = require('path');
module.exports = {
entry: './index.js',
output: {
path: './',
filename: 'app.js'
},
devServer: {
inline: true,
port: 3334
},
resolveLoader: { root: path.join(__dirname, "node_modules") },
module: {
loaders: [
{
test: /\.js$/,
exclude: '/node_modules',
loader: 'babel',
query: {
presets: ['es2015', 'react']
}
}
]
}
};
和我有以下項目的目錄結構:
├── actions.js
├── components
├── containers
├── index.js
├── node_modules
├── package.json
├── reducers.js
├── test.js
└── webpack.config.js
項目目錄的絕對路徑爲/home/dmitriy/WebstormProjects/Redux-todo
那麼爲什麼當我運行npm start
它崩潰,出現錯誤:
ERROR in (webpack)/~/process/browser.js Module build failed: Error: Couldn't find preset "es2015" relative to directory "/usr/local/lib/node_modules/webpack/node_modules/process"
這是什麼/usr/local/lib/node_modules/webpack/node_modules/process
路徑,以及爲什麼它說,它搜索相關呢?
谷歌搜索這個錯誤我發現,
IMPORTANT: The loaders here are resolved relative to the resource which they are applied to. This means they are not resolved relative the the configuration file. If you have loaders installed from npm and your node_modules folder is not in a parent folder of all source files, webpack cannot find the loader. You need to add the node_modules folder as absolute path to the resolveLoader.root option. (resolveLoader: { root: path.join(__dirname, "node_modules") })
應該修復它,但你可以看到我有它在我的配置,仍然看到此錯誤。
我在Ubuntu 16.04 LTS,版本的NodeJS是4.2.6,3.5.2 NPM
在父目錄中是否有任何.babelrc文件? – nitte93user3232918
不,沒有.babelrc – dKab