ReactJS环境安装错误

时间:2017-04-12 10:05:38

标签: reactjs webpack webpack-dev-server

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.output.path: The provided value "" is not an absolute path!
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! helloworldapp@1.0.0 start: `webpack-dev-server --hot`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the helloworldapp@1.0.0 start script 'webpack-dev-server --hot'.
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 helloworldapp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     webpack-dev-server --hot
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs helloworldapp
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls helloworldapp
npm ERR! There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/aakash/.npm/_logs/2017-04-12T09_51_55_188Z-debug.log

1 个答案:

答案 0 :(得分:0)

正如错误消息所示:

configuration.output.path: The provided value "" is not an absolute path!

为什么显示空字符串而不是output.path的实际值,我不知道 - 但无论如何,您的配置都是错误的。 output.path 的值是绝对路径,您将其设置为相对路径。

人们解决此问题的通常方法是从Node导入path模块,然后使用path.join,如下所示:

var path = require('path');

module.exports = {
    /// ...

    output: {
        path: path.resolve(__dirname, "dist"),
        filename: "index.js"
    },

    // ...
};

但是,由于您只是尝试将输出文件转储到根目录中,因此您可以放弃这样做:

// no path import needed

module.exports = {
    // ...

    output: {
        path: __dirname,
        filename: "index.js"
    },

    // ...
};