深入react技术栈-源码问题1

问题1 深入react技术栈源码第一次运行时报错--'NODE_ENV' 不是内部或外部命令,也不是可运行的程序或批处理文件。

在运行第二章的代码时,执行npm install 后运行代码时,报 ‘NODE_ENV’ 不是内部或外部命令,也不是可运行的程序或批处理文件。

image

解决方法

找到 package.json 文件 修改scripts其中的内容:

"scripts": {
    "start": "set NODE_ENV=dev && node ./server.js"
},

问题2

ERROR in ./js/Tabs.js
Module build failed: SyntaxError: F:/react/react-book-examples-master/02/js/Tabs.js: Decorators are not officially supported yet in 6.x pending a proposal update.
However, if you need to use them you can install the legacy decorators transform with:

npm install babel-plugin-transform-decorators-legacy --save-dev

and add the following line to your .babelrc file:

{
  "plugins": ["transform-decorators-legacy"]
}

The repo url is: https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy.

image

解决方法

这个问题是babel的版本问题,在高版本的babel中阻止实施装饰,需要我们添加一个特殊的插件 babel-plugin-transform-decorators-legacy

npm i --save-dev babel-plugin-transform-decorators-legacy

然后修改 .babelrc

{
  "presets": ["es2015", "stage-0", "react"],
  "plugins": [
    ["transform-decorators-legacy"],
    // ...
  ]
}

或者 Webpack

{
  test: /\.jsx?$/,
  loader: 'babel',
  query: {
    cacheDirectory: true,
    plugins: ['transform-decorators-legacy' ],
    presets: ['es2015', 'stage-0', 'react']
  }
}

参考链接

Webpack babel 6 ES6装饰

React.js 6.x正在等待提案更新中还不支持装饰器

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值