node bin/index.js
时,我的节点(6.9.0)脚本运行没有问题。
但是,当我尝试从$ PATH运行它时(通过在package.json中创建bin
条目并使用npm -g install .
或npm link
),我遇到了以下内容:
/home/peter/.nvm/versions/node/v6.9.0/bin/react-render-server: line 1: global.__RWR_ENV__: command not found
/home/peter/.nvm/versions/node/v6.9.0/bin/react-render-server: line 2: syntax error near unexpected token `'babel-core/register''
/home/peter/.nvm/versions/node/v6.9.0/bin/react-render-server: line 2: `require('babel-core/register');'
答案 0 :(得分:0)
您需要在节点脚本的顶部添加#!/usr/bin/env node
。请参阅此帖子What does "#!/bin/env" mean (at the top of a node.js script)?