gpt4 book ai didi

node.js - 模块构建失败 : ReferenceError: [BABEL]/app/src/index. js : Unknown option:/app/node_modules/react/react. js.Children

转载 作者:太空宇宙 更新时间:2023-11-03 21:53:23 25 4
gpt4 key购买 nike

我的项目失败,并在 Heroku 上出现标题中的错误消息,但它可以在本地运行。

这是我的webpack.config.js:

module.exports = {
entry: [
'./src/index.js'
],
output: {
path: __dirname,
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0']
}
}]
},
resolve: {
extensions: ['.jsx', '.js']
},
devServer: {
historyApiFallback: true,
contentBase: './'
}
};

这是package.json:

{
"main": "index.js",
"scripts": {
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
"test:watch": "npm run test -- --watch"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-1": "^6.24.1",
"chai": "^3.5.0",
"chai-jquery": "^2.0.0",
"jquery": "^2.2.1",
"jsdom": "^8.1.0",
"mocha": "^2.4.5",
"react-addons-test-utils": "^0.14.7"
},
"dependencies": {
"axios": "^0.17.1",
"lodash": "^3.10.1",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-redux": "4.3.0",
"react-router": "^2.0.1",
"react-router-dom": "^4.0.0",
"redux": "^3.0.4",
"redux-form": "^6.6.3",
"redux-promise": "^0.5.3",
"validator": "^9.1.2",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.4"
}
}

我进行了一些挖掘,试图找到答案,但没有出现在一台机器上工作,而在另一台机器上不工作的情况。

更新1

这是index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import promise from 'redux-promise';

import reducers from './reducers';

import LoginForm from './components/login_form';

const createStoreWithMiddleware = applyMiddleware(promise)(createStore);

ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<BrowserRouter>
<div>
<Route path="/" component={LoginForm} />
</div>
</BrowserRouter>
</Provider>
, document.querySelector('.container'));

** 更新 2 **我尝试将 webpack loader 配置对象中的 test 属性的 jsx 更改为 js,但没有帮助。我删除了 stage-1 但它仍然失败。

最佳答案

此问题已得到解决:

  1. 从 webpack 配置文件中删除了 module.queryresolve
  2. 将依赖项从 devDependency 移至 dependency(heroku 是生产环境,因此它不会下载 devDependencies,这也不会下载)对我来说很有意义!)

关于node.js - 模块构建失败 : ReferenceError: [BABEL]/app/src/index. js : Unknown option:/app/node_modules/react/react. js.Children,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47493130/

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