为什么运行npm run build时会出现此错误?

时间:2016-11-29 22:41:57

标签: node.js reactjs redux babeljs babel

我第一次跑:

npm install babel-core babel-loader --save-dev

然后我跑了:

npm run build

我得到以下错误:

> immutable-todo@1.0.0 build C:\Users\Ryan\Documents\to-do\immutable-redux-   todo
> webpack

Hash: 396f0bfb9d565b6f60f0
Version: webpack 1.13.3
Time: 1285ms
    + 1 hidden modules

ERROR in ./src/app.js
Module build failed: Error: Couldn't find preset "react" relative to  directory "C:\\Users\\Ryan\\Documents"
    at C:\Users\Ryan\Documents\to-do\immutable-redux- todo\node_modules\babel-core\lib\transformation\file\options\option
-manager.js:299:19
    at Array.map (native)
    at OptionManager.resolvePresets (C:\Users\Ryan\Documents\to- do\immutable-redux-todo\node_modules\babel-core\lib\tran
sformation\file\options\option-manager.js:270:20)
    at OptionManager.mergePresets (C:\Users\Ryan\Documents\to-do\immutable-    redux-todo\node_modules\babel-core\lib\transf
ormation\file\options\option-manager.js:259:10)
    at OptionManager.mergeOptions (C:\Users\Ryan\Documents\to-do\immutable-  redux-todo\node_modules\babel-core\lib\transf
ormation\file\options\option-manager.js:244:14)
    at OptionManager.init (C:\Users\Ryan\Documents\to-do\immutable-redux-  todo\node_modules\babel-core\lib\transformation
\file\options\option-manager.js:374:12)
    at File.initOptions (C:\Users\Ryan\Documents\to-do\immutable-redux-   todo\node_modules\babel-core\lib\transformation\f
ile\index.js:216:65)
    at new File (C:\Users\Ryan\Documents\to-do\immutable-redux-   todo\node_modules\babel-core\lib\transformation\file\inde
x.js:139:24)
    at Pipeline.transform (C:\Users\Ryan\Documents\to-do\immutable-redux-   todo\node_modules\babel-core\lib\transformation
\pipeline.js:46:16)
    at transpile (C:\Users\Ryan\Documents\to-do\immutable-redux-   todo\node_modules\babel-loader\lib\index.js:41:20)
    at Object.module.exports (C:\Users\Ryan\Documents\to-do\immutable-redux-  todo\node_modules\babel-loader\lib\index.js:
138:12)

这是我的package.json:

{
  "name": "immutable-todo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack",
    "watch": "webpack --watch"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "immutable": "^3.8.0",
    "react": "^0.14.6",
    "react-dom": "^0.14.6",
    "react-redux": "^4.4.5",
    "redux": "^3.4.0"
  },
  "devDependencies": {
    "babel-core": "^6.18.2",
    "babel-loader": "^6.2.8",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "webpack": "^1.13.0"
  }
}

我一直试图搜索这四个很长一段时间而没有运气,你能帮助我理解我做错了什么以及我需要解决的问题吗? 谢谢。

这是我的webpack.config.js:

 module.exports = {
   entry: './src/app.js',
  output: {
    path: __dirname,
    filename: 'bundle.js'
  },
   module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel',
        query: { presets: [ 'es2015', 'react' ] }
      }
    ]
  }
};

0 个答案:

没有答案