使用babel进行编译时出错

时间:2016-02-17 06:48:43

标签: node.js reactjs webpack babeljs redux-form

我需要 redux-form-3.0.8 并从github下载源代码

我尝试执行' npm run build '来编译它,但是出现了以下错误。

C:\Users\xxxxx\Downloads\redux-form-3.0.8\redux-form-3.0.8>npm run build

> redux-form@3.0.8 build C:\Users\xxxxx\Downloads\redux-form-3.0.8\redux-form-
3.0.8
> npm run build:lib && npm run build:umd && npm run build:umd:min


> redux-form@3.0.8 build:lib C:\Users\xxxxx\Downloads\redux-form-3.0.8\redux-f
orm-3.0.8
> babel src --out-dir lib

ReferenceError: [BABEL] src\actions.js: Unknown option: C:\Users\xxxxx\Downloa
ds\redux-form-3.0.8\redux-form-3.0.8\.babelrc.stage
    at Logger.error (C:\Users\xxxxx\AppData\Roaming\npm\node_modules\babel-cli
\node_modules\babel-core\lib\transformation\file\logger.js:41:11)
    at OptionManager.mergeOptions (C:\Users\xxxxx\AppData\Roaming\npm\node_mod
ules\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-ma
nager.js:262:18)
    at OptionManager.addConfig (C:\Users\xxxxx\AppData\Roaming\npm\node_module
s\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-manag
er.js:221:10)
    at OptionManager.findConfigs (C:\Users\xxxxx\AppData\Roaming\npm\node_modu
les\babel-cli\node_modules\babel-core\lib\transformation\file\options\option-man
ager.js:364:16)
    at OptionManager.init (C:\Users\xxxxx\AppData\Roaming\npm\node_modules\bab
el-cli\node_modules\babel-core\lib\transformation\file\options\option-manager.js
:412:12)
    at File.initOptions (C:\Users\xxxxx\AppData\Roaming\npm\node_modules\babel
-cli\node_modules\babel-core\lib\transformation\file\index.js:190:75)
    at new File (C:\Users\xxxxx\AppData\Roaming\npm\node_modules\babel-cli\nod
e_modules\babel-core\lib\transformation\file\index.js:121:22)
    at Pipeline.transform (C:\Users\xxxxx\AppData\Roaming\npm\node_modules\bab
el-cli\node_modules\babel-core\lib\transformation\pipeline.js:42:16)
    at transform (C:\Users\xxxxx\AppData\Roaming\npm\node_modules\babel-cli\li
b\babel\util.js:53:22)
    at Object.compile (C:\Users\xxxxx\AppData\Roaming\npm\node_modules\babel-c
li\lib\babel\util.js:62:12)

我发现' npm run build '首先会在 package.json 中调用' babel src --out-dir lib ' 。所以这个错误是由 babel 命令引发的。

以下是我的babel版本。 C:\ Users \ xxxxxx \ node_modules \ redux-form> babel --version 6.2.0(babel-core 6.2.1)

你能告诉我如何绕过这个问题吗?感谢。

我知道我可以直接安装下面编译的版本,但它仍然有错误,我很沮丧。

C:\Users\xxxxx\node_modules>npm install redux-form@3.0.8
npm WARN checkPermissions Missing write access to C:\Users\xxxxx\node_modules\
redux-form
gulp@3.9.0 C:\Users\xxxxx
├── UNMET PEER DEPENDENCY babel-core@*
├── UNMET PEER DEPENDENCY react-redux@^3.0.0 || ^4.0.0
├── redux-form@3.0.8  extraneous
└── UNMET PEER DEPENDENCY webpack@*

npm WARN EPEERINVALID babel-loader@5.3.2 requires a peer of babel-core@* but non
e was installed.
npm WARN EPEERINVALID babel-loader@5.3.2 requires a peer of webpack@* but none w
as installed.
npm WARN EPEERINVALID redux-form@3.0.8 requires a peer of react-redux@^3.0.0 ||
^4.0.0 but none was installed.
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\xxxxx\\AppData
\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install" "redux-form@3.0.8"

npm ERR! node v4.1.1
npm ERR! npm  v3.3.6
npm ERR! path C:\Users\xxxxx\node_modules\redux-form
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall access

npm ERR! enoent ENOENT: no such file or directory, access 'C:\Users\xxxxx\node
_modules\redux-form'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\xxxxx\node_modules\npm-debug.log

1 个答案:

答案 0 :(得分:2)

因为babel 6与旧的.babelrc不兼容

以下是一些解决方案:

  1. 尝试删除所有.babelrc并在webpack config.js中添加选项
  2. 使用babel 5
  3. 价: https://github.com/babel/babel-loader/issues/132