【问题标题】:Error when compiling with babel使用 babel 编译时出错
【发布时间】:2016-05-28 17:55:23
【问题描述】:

我需要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

【问题讨论】:

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


    【解决方案1】:

    因为 babel 6 不兼容旧的 .babelrc

    这里有一些解决方案:

    1. 尝试删除所有 .babelrc 并将选项添加到您的 webpack config.js 中
    2. 使用 babel 5

    参考: https://github.com/babel/babel-loader/issues/132

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-17
      • 1970-01-01
      • 1970-01-01
      • 2017-11-22
      • 2016-10-27
      • 2017-10-24
      • 1970-01-01
      相关资源
      最近更新 更多