【问题标题】:Can anyone let me know why am I getting this error?谁能让我知道为什么会出现此错误?
【发布时间】:2016-10-03 06:24:37
【问题描述】:

我刚开始学习 ReactJSNodeJS 并尝试通过 NPM 运行应用程序,但刚开始我收到以下错误:

You MUST specify an outfile with -o.

我的启动命令:

watchify src/main.jsx -v -t [ babelify --presets [ react ]] -o public/js/main.js

整个错误:

C:\Users\Umair Shah Yousafzai\react-skeleton>npm start

> react-skeleton@1.0.0 start C:\Users\Umair Shah Yousafzai\react-skeleton 
> watchify src/main.jsx -v -t [ babelify --presets [ react ]] -o public/js/main.js

You MUST specify an outfile with -o.

npm ERR! Windows_NT 10.0.10240
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "start"
npm ERR! node v6.2.0
npm ERR! npm v3.8.9
npm ERR! code ELIFECYCLE
npm ERR! react-skeleton@1.0.0 start: watchify src/main.jsx -v -t [ babelify --presets [ react ]] -o public/js/main.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-skeleton@1.0.0 start script 'watchify src/main.jsx -v -t [ babelify --presets [ react ]] -o public/js/main.js'.
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 react-skeleton package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! watchify src/main.jsx -v -t [ babelify --presets [ react ]] -o public/js/main.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs react-skeleton
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls react-skeleton
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\Umair Shah Yousafzai\react-skeleton\npm-debug.log

我努力解决它:

我已尝试删除 node_modules 文件夹,然后运行返回 npm install 但我仍然收到相同的错误我的 NPM 版本是 3.8.9

我的文件:

main.jsx

var React = require('react');
var ReactDOM = require('react-dom');
var List = require('./components/List.jsx');

ReactDOM.render(<List />, document.getElementById('ingredients'));

List.jsx

var React = require('react');
var Listitem = require('./Listitem.jsx');

var ingredients = [{"id":1,"text":"ham"},{"id":2,"text":"cheese"},{"id":3,"text":"potatos"}];

var List = React.createClass({
    render: function() {
        var listItems = ingredients.map(function(item) {
            return <Listitem key={item.id} ingredient={item.text} />
        });
        return (<ul>{listItems}</ul>);
    }

});

module.exports = List;

Listitem.jsx

var React = require('react');
var Listitem = React.createClass({
    render: function() {
          return (
            <li>
                <h4>{this.props.ingredient}</h4>
            </li>
          );
     }

});

module.exports = ListItem;

【问题讨论】:

    标签: javascript node.js reactjs npm watchify


    【解决方案1】:

    尝试将 -o {src} 作为第一个选项; -t 选项的子参数语法可能会在这里混乱。

    watchify src/main.jsx -o public/js/main.js -v -t [ babelify --presets [ react ]]
    

    另外,您需要修复 jsx 文件。

    main.jsx:

    ReactDOM.render("<List />", document.getElementById('ingredients'));
    

    列表.jsx:

    return "<Listitem key={item.id} ingredient={item.text} />"
    
    return "<ul>{listItems}</ul>";
    

    Listitem.jsx:

    return "<li><h4>{this.props.ingredient}</h4></li>";
    

    【讨论】:

    • 通过添加您的代码,我现在收到以下错误:Error: Parsing file C:\Users\Umair Shah Yousafzai\react-skeleton\src\main.jsx: Unexpected token (5:16)
    • @UmairShahYousafzai 好吧,这是另一个(不相关的)错误 - 您可能需要修复您的 jsx 文件。但我想原来的问题现在已经解决了。
    • 我正在用main.jsx 文件更新我的问题..!
    • @UmairShahYousafzai 行:ReactDOM.render(, document.getElementById('ingredients'));必须是 ReactDOM.render("", document.getElementById('ingredients'));
    • @UmairShahYousafzai(将 括在引号中)
    猜你喜欢
    • 2011-07-23
    • 2023-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 2020-11-25
    • 1970-01-01
    相关资源
    最近更新 更多