npm run dev命令不适用于vuejs的hackernews示例

时间:2017-08-10 10:16:36

标签: javascript node.js npm webpack vue.js

我正在尝试从vuejs'github repository运行vue-hackernews-2.0示例

在设置部分,它解释了如何安装项目:

# install dependencies
npm install # or yarn

# serve in dev mode, with hot reload at localhost:8080
npm run dev

# build for production
npm run build

# serve in production mode
npm start

我做了npm安装。在server.js中将端口更改为8888后,我在命令行上键入了“npm run dev”。

> vue-hackernews-2.0@ dev D:\Users\212399486\WebstormProjects\vue-hackernews-2.0-master
> node server

server started at localhost:8888


DONE  Compiled successfully in 16328ms                                                                                                                                                                                                                        1:02:18 PM


DONE  Compiled successfully in 17845ms                                                                                                                                                                                                                        1:02:19 PM


webpack built bd162a76119031a85eed in 17845ms

当我去localhost时:8888它只会尝试加载1分钟然后失败,控制台上没有任何东西。

我想我也应该尝试“npm run build”和“npm start”,所以我也使用了两个命令。 “npm run build”成功创建了dist文件。

但是在“npm start”之后我收到了这个错误:

> vue-hackernews-2.0@ start D:\Users\212399486\WebstormProjects\vue-hackernews-2.0-master
> cross-env NODE_ENV=production node server

module.js:471
    throw err;
    ^

Error: Cannot find module './dist/vue-ssr-server-bundle.json'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (D:\Users\212399486\WebstormProjects\vue-hackernews-2.0-master\server.js:41:18)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: spawn node ENOENT
    at notFoundError (D:\Users\212399486\WebstormProjects\vue-hackernews-2.0-master\node_modules\cross-spawn\lib\enoent.js:11:11)
    at verifyENOENT (D:\Users\212399486\WebstormProjects\vue-hackernews-2.0-master\node_modules\cross-spawn\lib\enoent.js:46:16)
    at ChildProcess.cp.emit (D:\Users\212399486\WebstormProjects\vue-hackernews-2.0-master\node_modules\cross-spawn\lib\enoent.js:33:19)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "D:\\Users\\212399486\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.11.2
npm ERR! npm  v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! vue-hackernews-2.0@ start: `cross-env NODE_ENV=production node server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the vue-hackernews-2.0@ start script 'cross-env NODE_ENV=production node server'.
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 vue-hackernews-2.0 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     cross-env NODE_ENV=production node server
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs vue-hackernews-2.0
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls vue-hackernews-2.0
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     D:\Users\212399486\WebstormProjects\vue-hackernews-2.0-master\npm-debug.log

dist文件夹的屏幕截图:

enter image description here

package.json脚本:

"scripts": {
    "dev": "node server",
    "start": "cross-env NODE_ENV=production node server",
    "build": "rimraf dist && npm run build:client && npm run build:server",
    "build:client": "cross-env NODE_ENV=production webpack --config build/webpack.client.config.js --progress --hide-modules",
    "build:server": "cross-env NODE_ENV=production webpack --config build/webpack.server.config.js --progress --hide-modules"
  },

2 个答案:

答案 0 :(得分:4)

  

需要Node.js 7 +

我设法让它没有任何问题。

$node -v
v8.3.0
$npm -v
5.3.0

成功更改默认端口:

要更改默认端口,您必须编辑package.json脚本:

dev:cross-env PORT=8888 node server

开始:cross-env PORT=8888 NODE_ENV=production node server

然后运行npm run dev

> vue-hackernews-2.0@ dev /home/emx/so/vue-hackernews-2.0
> cross-env PORT=8888 node server

server started at localhost:8888

答案 1 :(得分:0)

您使用的是不受支持的节点版本。您的错误指向node v6.11.2,请参阅下文。

 npm ERR! Windows_NT 6.1.7601
 npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "D:\\Users\\212399486\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
 npm ERR! node v6.11.2
 npm ERR! npm  v3.10.8

vue-hackernews-2.0需要Node.js 7+。将您的节点升级到7+版本,你应该没问题。我还建议您更新您的npm版本。

如果您需要说明,请参阅the answers to this question以获取有关如何更新节点版本的详细信息。