Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 支持此项目的express webpack和babel_Reactjs_Webpack_Babeljs - Fatal编程技术网

Reactjs 支持此项目的express webpack和babel

Reactjs 支持此项目的express webpack和babel,reactjs,webpack,babeljs,Reactjs,Webpack,Babeljs,我正在尝试将Express添加到此网站,但在运行脚本时出现此错误npm run webpack: ERROR in ./src/index.js 11:3 Module parse failed: Unexpected token (11:3) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See http

我正在尝试将Express添加到此网站,但在运行脚本时出现此错误
npm run webpack

ERROR in ./src/index.js 11:3
Module parse failed: Unexpected token (11:3)
You may need an appropriate loader to handle this file type, currently no
loaders are configured to process this file.
See https://webpack.js.org/concepts#loaders
    |
    | ReactDOM.render(
    >    <ProductProvider>
    |       <Router>
    |           <App />

.babelrc


我本以为这会起作用,但我一直在犯这个错误。我需要帮助。我是新来的。我试着做我所知道的一切,但它总是说那个错误。

什么是
/src/index.js
包含的?它是您的React代码的入口点吗?您是否正在尝试使用Webpack编译您的Express应用程序?从“React”导入React;从“react dom”导入react dom;导入“./index.css”;从“./App”导入应用程序;从“react Router dom”导入{BrowserRouter as Router};从“./context”导入{ProductProvider};将*作为serviceWorker从“/serviceWorker”导入;ReactDOM.render(,document.getElementById('root'));这就是index.js包含的内容,是的,我正在尝试用Webpack编译express应用程序。你能确认你已经安装了
babel loader
及其预设吗?是的,我已经安装了它。错误基本上是Webpack,说明它不理解JSX
babel loader
以及
@babel/core
中的预设。babelrc
应该能够编译JSX代码。此时,Express与您的错误无关。你能发布你的
包.json吗?
module.exports = {
  entry: "./src/index.js",
  output: {
    path: __dirname + "public",
    filename: "bundle.js"
  },

  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: ["babel-loader"]
      },
      {
        test: /\.css$/i,
        use: ["style-loader", "css-loader"]
      }
    ]
  }
};
{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ],
  "plugins": [
    [
      "@babel/plugin-proposal-class-properties",
      {
        "loose": true
      }
    ],
    [
      "react-css-modules", 
      { 
        "option": "value" 
      } 
    ]
  ]
}