calpa / gatsby-starter-calpa-blog

Calpa's Blog (GatsbyJS Starter X Netlify CMS)
https://v1.calpa.me/
MIT License
333 stars 60 forks source link

关于 NODE_ENV=development #120

Closed 1v9 closed 5 years ago

1v9 commented 5 years ago

环境

$ npm version
{ blog: '1.0.0',
  npm: '6.4.1',
  ares: '1.15.0',
  cldr: '34.0',
  http_parser: '2.8.0',
  icu: '63.1',
  llhttp: '1.0.1',
  modules: '67',
  napi: '3',
  nghttp2: '1.34.0',
  node: '11.4.0',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.24.0',
  v8: '7.0.276.38-node.13',
  zlib: '1.2.11' }

Windows 下一直报错如下

$ npm start

> blog@1.0.0 start C:\Code\test
> npm run fetch:config && npm run develop

> blog@1.0.0 fetch:config C:\Code\test
> NODE_ENV=development node ./scripts/index.js

'NODE_ENV' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! blog@1.0.0 fetch:config: `NODE_ENV=development node ./scripts/index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the blog@1.0.0 fetch:config 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\mkb\AppData\Roaming\npm-cache\_logs\2018-12-16T04_09_04_527Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! blog@1.0.0 start: `npm run fetch:config && npm run develop`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the blog@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\mkb\AppData\Roaming\npm-cache\_logs\2018-12-16T04_09_04_619Z-debug.log

尝试直接指定 config 后可以成功运行

// ./package.json
"fetch:config": "node ./scripts/index.js",

// ./gatsby/getPosts.js
require('dotenv').config({
  path: `.env.development`,
});

我不是程序员,所以也不太理解是什么原因,另外中文文档里配置文件缺一行

API_BASE_URL = 'https://cdn.contentful.com'
calpa commented 5 years ago

@1v9 感谢你的反馈,这确实是个问题。 这里做的是把 node 环境设置为开发模式(development) 以下命令应该可以执行

$env:NODE_ENV="development" node ./scripts/index.js

另外,文档没有及时更新。。。

这里是说把获取数据的地址改为 https://cdn.contentful.com

API_BASE_URL = 'https://cdn.contentful.com'

https://stackoverflow.com/questions/9249830/how-can-i-set-node-env-production-on-windows

1v9 commented 5 years ago

@calpa 谢谢你的解答。

我发现一个有趣的 repo 支持 一键导入 Netlify,感觉你可以尝试一下,这样像我这样的小白用户可以享受真正的开箱即用😘