我正在尝试与webpack和babel建立一个简单的反应项目。在我第一次构建时遇到问题。
webpack.config.js
const webpack = require('webpack');
const path = requrie('path');
module.exports = {
entry: {
app: './src/main.js'
},
output: {
path: path.resolve(__dirname, 'build'),
filename: 'main.js'
},
module: {
loaders: [
{
test: /\.js?$/,
exclude: /mode_modules/,
loader: 'babel-loader',
query: {
presets: ['react', 'env']
}
}
]
},
target: 'web'
};
的package.json
{
"name": "main-script",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"react": "^16.3.0",
"react-dom": "^16.3.0",
"webpack": "^4.4.1",
"webpack-cli": "^2.0.13",
"webpack-dev-server": "^3.1.1"
}
}
我收到以下错误:
C:\main-script\node_modules\webpack-cli\bin\webpack.js:242
throw err;
^
ReferenceError: requrie is not defined
at Object.<anonymous> (C:\main-script\webpack.config.js:2:14)
at Module._compile (C:\main-script\node_modules\v8-compile-cache\v8-compile-cache.js:178:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (C:\main-script\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
at WEBPACK_OPTIONS (C:\main-script\node_modules\webpack-cli\bin\convert-argv.js:133:13)
at requireConfig (C:\main-script\node_modules\webpack-cli\bin\convert-argv.js:135:6)
at C:\main-script\node_modules\webpack-cli\bin\convert-argv.js:142:17
at Array.forEach (<anonymous>)
at module.exports (C:\main-script\node_modules\webpack-cli\bin\convert-argv.js:140:15)
at yargs.parse (C:\main-script\node_modules\webpack-cli\bin\webpack.js:239:39)
at Object.parse (C:\main-script\node_modules\webpack-cli\node_modules\yargs\yargs.js:543:18)
at C:\main-script\node_modules\webpack-cli\bin\webpack.js:217:8
at Object.<anonymous> (C:\main-script\node_modules\webpack-cli\bin\webpack.js:512:3)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\main-script\node_modules\webpack\bin\webpack.js:80:2)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! main-script@1.0.0 build: `webpack`
npm ERR! Exit status 1
我在网上搜索了会遇到类似错误的人。他们通常通过添加target:'web'
来解决此问题,这是默认设置。我确定已经添加了,但我仍然没有运气。
为什么会这样?