我无法使用webpack运行我的React应用程序。我遇到了一个我无法理解的错误。
尝试运行构建时,我的终端上出现以下错误:
该命令的语法不正确。
npm ERR!代码ELIFECYCLE
npm ERR!错误1
npm ERR! reactjs-basics@1.0.0 build:
webpack -d && copy src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot
npm ERR!退出状态1
npm ERR!
npm ERR!在reactjs-basics@1.0.0构建脚本中失败。
npm ERR!这可能不是npm的问题。上面可能有额外的日志记录输出。
npm ERR!可以在以下位置找到此运行的完整日志:
npm ERR! C:\用户\ PRATIK \应用程序数据\漫游\ NPM-cache_logs \ 2018-05-06T07_21_12_207Z-的debug.log
npm ERR!代码ELIFECYCLE
npm ERR!错误1
npm ERR! reactjs-basics@1.0.0 start:
npm run build
npm ERR!退出状态1
npm ERR!
npm ERR!在reactjs-basics@1.0.0启动脚本中失败。
npm ERR!这可能不是npm的问题。上面可能有额外的日志记录输出。
npm ERR!可以在以下位置找到此运行的完整日志:
npm ERR! C:\用户\ PRATIK \应用程序数据\漫游\ NPM-cache_logs \ 2018-05-06T07_21_12_256Z-的debug.log
Package.json文件如下:
{
"name": "reactjs-basics",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "npm run build",
"build": "webpack -d && copy src/index.html dist/index.html && webpack-dev-server --content-base src/ --inline --hot",
"build:prod": "webpack -p && copy src/index.html dist/index.html"
},
"keywords": [
"reactjs"
],
"author": "Pratik Basak",
"license": "ISC",
"devDependencies": {
"babel-loader": "^7.1.4",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"webpack": "^4.7.0",
"webpack-cli": "^2.1.2",
"webpack-dev-server": "^3.1.4"
}
}
webpack.config.js文件如下:
const webpack = require('webpack');
const path = require('path');
const DIST_DIR = path.resolve(__dirname, 'dist');
const SRC_DIR = path.resolve(__dirname, 'src');
var config = {
entry: SRC_DIR + '/app/index.js',
output: {
path: DIST_DIR + '/app',
filename: 'bundle.js',
publicPath: '/app/'
},
module: {
rules: [
{
test: /\.js?/,
include: SRC_DIR,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-2']
}
}
]
}
};
module.exports = config;