反应项目设置-npm运行webpack问题 [英] react project setup - npm run webpack issue

查看:228
本文介绍了反应项目设置-npm运行webpack问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注 http://ccoenraets.github.io/es6-tutorial -react/setup/用于反应项目的设置.最后,运行

I am following http://ccoenraets.github.io/es6-tutorial-react/setup/ for react project setup. In the end part, I am getting this error after running

npm run webpack

我遇到错误-

npm run webpack

> project-newborn@1.0.0 webpack /home/rishi/Desktop/project-newborn
> webpack

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module has an unknown property 'loaders'. These properties are valid:
   object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? }
   -> Options affecting the normal modules (`NormalModuleFactory`).

npm ERR! Linux 4.15.0-34-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "webpack"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! project-newborn@1.0.0 webpack: `webpack`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the project-newborn@1.0.0 webpack script 'webpack'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the project-newborn package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     webpack
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs project-newborn
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls project-newborn
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/rishi/Desktop/project-newborn/npm-debug.log

推荐答案

在使用 Webpack 4 时,您必须使用rules代替loaders,最好使用use代替loader.

When using Webpack 4 you must use rules instead of loaders and it's better to use use instead of loader.

 var path = require('path');
 var webpack = require('webpack');

 module.exports = {
     entry: './js/app.js',
     output: {
         path: path.resolve(__dirname, 'build'),
         filename: 'app.bundle.js'
     },
     module: {
         rules: [
             {
                 test: /\.js$/,
                 use: [
                     {
                         loader: 'babel-loader',
                         options: {
                             presets: ['es2015', 'react'],
                         },
                     },
                 ],
             }
         ]
     },
     stats: {
         colors: true
     },
     devtool: 'source-map'
 };

这篇关于反应项目设置-npm运行webpack问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆