nuxt升级到nuxt2过程踩坑

jackieli@DESKTOP-1U117IU MINGW64 /f/jackieli/my-github/nuxt-blog (master)
$ npm install nuxt@2.0.0 --save


"nuxt-edge": "^2.0.0-25428457.c59acdd",(这个可以)
"nuxt": "^2.0.0",(打包可以 但是 npm start 失败)
"nuxt": "npm:nuxt-edge",

用nuxt ^2.0.0 启动nodemon server.js 报错例如 删除重新安装

jackieli@DESKTOP-1U117IU MINGW64 /f/jackieli/my-github/nuxt-blog (master)
$ nodemon server.js
[nodemon] 1.18.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server.js`
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module 'color-convert'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (F:\jackieli\my-github\nuxt-blog\node_modules\ansi-styles\index.js:2:22)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
[nodemon] app crashed - waiting for file changes before starting...

需要 npm install color-convert --save

这个就是个组合安装 配套

 "color-convert": "^1.9.3",
   "nuxt": "^2.0.0"

运行 npm run dev || nodemon server.js

$ npm run dev

> nuxt-blog@0.0.1 dev F:\jackieli\my-github\nuxt-blog
> nuxt dev

[11:58:33] vendor has been deprecated due to webpack4 optimization
[11:58:33] Building project
[11:58:35] Builder initialized
[11:58:35] Nuxt files generated
[11:58:36] Compiling client
[11:58:36] Compiling server
(node:54716) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
[11:58:45] Compiled server in 9s
[11:58:46] Compiled client in 10s
[11:58:46] Listening on http://localhost:3000

$ nodemon server.js
[nodemon] 1.18.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server.js`
[12:00:36] vendor has been deprecated due to webpack4 optimization
[12:00:36] Building project
服务器运行于 localhost:3001


NUXT1.X 版本

jackieli@DESKTOP-1U117IU MINGW64 /f/jackieli/my-github/nuxt-blog (master)
$ NODE_ENV=production PORT=3333 node server.js
[12:58:29] vendor has been deprecated due to webpack4 optimization
服务器运行于 localhost:3333
sitemap 脚本更新成功 2018-09-27T04:58:35.857Z
文章数组 39

nuxt2版本 "PORT=3001 制定启动失败 去掉PORT=3001 默认3000可以启动成功

"start": "PORT=3001 nuxt start", (版本nuxt1.x 可以这样使用没毛病)

Entrypoint app = server-bundle.js server-bundle.js.map

> nuxt-blog@0.0.1 start F:\jackieli\my-github\nuxt-blog
> PORT=3001 nuxt start

'PORT' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nuxt-starter@1.0.0 start: `PORT=3333 nuxt start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nuxt-starter@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\jackieli\AppData\Roaming\npm-cache\_logs\2018-09-27T04_55_00_876Z-debug.log


"start": "nuxt start -p 3001 -H 0.0.0.0", 正确的使用 是

nuxt2 spa 服务端和客户端两种 模式

 "scripts": {
    "dev": "nuxt dev",
    "dev": "nuxt -p 3000 -H 0.0.0.0", //dev 可以去掉 -p 后面的也可以去掉
    "dev-spa": "nuxt --spa",
    "dev-spa": "nuxt --spa -p 3000 -H 0.0.0.0",
    "build": "nuxt build",
    "build-spa": "nuxt build --spa",
    "analyze": "nuxt build --analyze",
    "prestart": "npm run build",
    "start": "nuxt start -p 3001 -H 0.0.0.0",
    "start-spa": "nuxt start --spa -p 3001 -H 0.0.0.0",
    "generate": "nuxt generate"
  },