我正在尝试运行webpac-dev-server --hot但它无法运行

时间:2018-04-15 06:50:41

标签: node.js reactjs

我正在尝试运行webpac-dev-server --hot但它无效。



I am trying to run webpack server but its giving me error;
C:\ReactJS>npm run it
> reactjs@1.0.0 it C:\ReactJS
> webpack-dev-server --hot
C:\ReactJS\webpack.config.js:7
        path: path.resolve(_dirname, 'output'),
                           ^
ReferenceError: _dirname is not defined
    at Object.<anonymous> (C:\ReactJS\webpack.config.js:7:28)
    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 WEBPACK_OPTIONS (C:\ReactJS\node_modules\webpack-cli\bin\convert-argv.js:
133:13)
at requireConfig (C:\ReactJS\node_modules\webpack-cli\bin\convert-argv.js:13
5:6)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactjs@1.0.0 it: `webpack-dev-server --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactjs@1.0.0 it script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\TechGeek\AppData\Roaming\npm-cache\_logs\2018-04-15T05_40_
14_638Z-debug.log
var path = require('path');
module.exports = {
    entry: './script.js',
    output: {
        path: path.resolve(__dirname, 'output'),
        filename: 'transpiled.js',
},
    module: {
    loaders: [
            {
                test: /\.jsx?$/,
                loader: 'babel-loader',
				exclude: /node_modules/,
                query: {
                presets: ['es2015', 'react']
}
}
]
}
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

当您只有一个webpack.config.js时,它应该是__dirname(带有两个下划线):

path.resolve(_dirname, 'output'),