gpt4 book ai didi

node.js - 未知选项 : . ../.babelrc.presets

转载 作者:IT老高 更新时间:2023-10-28 22:04:13 26 4
gpt4 key购买 nike

我在 es2015 中使用 Babel 6 并且 react 需要 babel-preset-es2015babel-preset-react

我在 .babelrc 中添加了 presets 属性,但它抛出了一个错误:

ERROR in ./src/client/entry.js
Module build failed: ReferenceError: [BABEL] /Users/brick/Dropbox/learncoding/node.js/isomorphic/src/client/entry.js: Unknown option: /Users/brick/Dropbox/learncoding/node.js/isomorphic/.babelrc.presets
at Logger.error (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/logger.js:58:11)
at OptionManager.mergeOptions (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/options/option-manager.js:126:29)
at OptionManager.addConfig (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/options/option-manager.js:107:10)
at OptionManager.findConfigs (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/options/option-manager.js:168:35)
at OptionManager.init (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/options/option-manager.js:229:12)
at File.initOptions (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/index.js:147:75)
at new File (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/index.js:137:22)
at Pipeline.transform (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/pipeline.js:164:16)
at transpile (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-loader/index.js:12:22)
at Object.module.exports (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-loader/index.js:69:12)
@ multi main

我的 .babelrc 文件是:

{
"presets": [
"es2015",
"react"
]
}

我可以运行 babel src -d lib 命令,它可以工作。但是如果我通过package.json运行npm start来运行babel,就会出现错误。

我想我可以忽略该错误,因为应用程序正在运行。但我想知道为什么会出现这个错误,但不确定它会影响什么。

我在 package.json 中的 scripts 是:

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "rm -rf lib",
"build": "npm run clean && /usr/local/bin/babel src -d lib --experimental",
"server": "nodemon lib/server/server",
"dev-server": "node lib/server/webpack",
"watch-js": "/usr/local/bin/babel src -d lib --experimental -w",
"start": "npm run watch-js & npm run dev-server & npm run server"
},

我的 entry.js

import React from "react";
import Router from "react-router";
import ReactDOM from "react-dom";
import routes from "./routes";
import DataWrapper from './DataWrapper';
import createBrowserHistory from 'history/lib/createBrowserHistory';

let history = createBrowserHistory();
var data = JSON.parse(document.querySelector('#data').innerHTML);
ReactDOM.render(<DataWrapper data={data}><Router history = {history}>{routes}</Router></DataWrapper>, document.querySelector('#app'));

最佳答案

我发现这个问题是由 babel-loaderbabel-core 的版本引起的。

package.json 中声明了依赖项 ^5.3.3,因此它不会更新到 6.x。将其更改为 >=5.3.3^6.0.0

^ 表示升级子版本,不升级主版本。

关于node.js - 未知选项 : . ../.babelrc.presets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33685365/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com