从PATH中找不到模块“ babel-preset-env”,您是说“ @ babel / env”吗?

时间:2020-03-14 19:16:34

标签: reactjs web webpack babeljs

我在带有Django服务器的React上有一个应用程序,当使用npm run dev时,出现错误

此处是完整的错误消息:
../phonemanager/frontend/src/index.js中的错误 模块构建失败(来自../node_modules/babel-loader/lib/index.js): 错误:无法从“ C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app”中找到模块“ babel-preset-env” -您的意思是“ @ babel / env”吗? 在Function.resolveSync [作为同步]处(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules \ resolve \ lib \ sync.js:81:15) 位于resolveStandardizedName(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules @ babel \ core \ lib \ config \ files \ plugins.js:101:31)
在resolvePreset(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules @ babel \ core \ lib \ config \ files \ plugins.js:58:10) 在loadPreset(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules @ babel \ core \ lib \ config \ files \ plugins.js:77:20) 在createDescriptor(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules @ babel \ core \ lib \ config \ config-descriptors.js:154:9) 在C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules @ babel \ core \ lib \ config \ config-descriptors.js:109:50 在Array.map() 在createDescriptors(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules @ babel \ core \ lib \ config \ config-descriptors.js:109:29) 在createPresetDescriptors(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules @ babel \ core \ lib \ config \ config-descriptors.js:101:10)中
在C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules @ babel \ core \ lib \ config \ config-descriptors.js:58:104 在cachedFunction(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules @ babel \ core \ lib \ config \ caching.js:62:27) 在cachedFunction.next() 在EvaluationSync(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules \ gensync \ index.js:244:28) 同步时(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules \ gensync \ index.js:84:14) 在预设位置(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules @ babel \ core \ lib \ config \ config-descriptors.js:29:84) 在mergeChainOpts(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules @ babel \ core \ lib \ config \ config-chain.js:320:26) 在Function.sync(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules \ gensync \ index.js:84:14) 在对象。 (C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules @ babel \ core \ lib \ config \ index.js:41:61) 在对象。 (C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules \ babel-loader \ lib \ index.js:144:26) 在Generator.next() 在asyncGeneratorStep(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules \ babel-loader \ lib \ index.js:3:103) 在_next(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules \ babel-loader \ lib \ index.js:5:194) 在C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules \ babel-loader \ lib \ index.js:5:364 在新的Promise() 在对象。 (C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules \ babel-loader \ lib \ index.js:5:97) 在Object._loader(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules \ babel-loader \ lib \ index.js:224:18) 在Object.loader(C:\ Users \ assmy \ OneDrive \Рабочийстол\ react-redux-django-app \ node_modules \ babel-loader \ lib \ index.js:60:18)

package.json:

{
  "name": "react-redux-django-app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "webpack --mode development ./phonemanager/frontend/src/index.js --output ./phonemanager/frontend/static/frontend/main.js",
    "build": "webpack --mode production ./phonemanager/frontend/src/index.js --output ./phonemanager/frontend/static/frontend/main.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.8.7",
    "@babel/preset-env": "^7.8.7",
    "@babel/preset-react": "^7.8.3",
    "babel-loader": "^8.0.6",
    "babel-plugin-import": "^1.13.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "css-loader": "^3.4.2",
    "extract-text-webpack-plugin": "^3.0.2",
    "less": "^2.7.0",
    "less-loader": "^5.0.0",
    "less-vars-to-js": "^1.3.0",
    "style-loader": "^1.1.3",
    "webpack": "^4.42.0",
    "webpack-cli": "^3.3.11"
  },
  "dependencies": {
    "antd": "^4.0.2",
    "antd-dayjs-webpack-plugin": "0.0.8",
    "prop-types": "^15.7.2",
    "react": "^16.13.0",
    "react-dom": "^16.13.0"
  }
}

.babelrc:

{
    "presets": ["@babel/preset-env", "@babel/preset-react"],
    "plugins": [
        ["transform-class-properties"],
        ["import", {"libraryName": "antd", "style": true} ]
]
}

webpack.config.js:

const path = require('path');
const webpack = require('webpack');
const fs = require('fs');
const lessToJs = require('less-vars-to-js');
const themeVariables = lessToJs(fs.readFileSync(path.join(__dirname, 'ant-theme-vars.less'), 'utf8'));

module.exports = {
  watch: true,
  context: path.resolve(__dirname, "./src"),
  entry: {
    app: "./index.js"
  },
  output: {
    path: path.resolve(__dirname, "./dist"),
    filename: "[name].bundle.js"
  },
  devtool: "source-map",
  resolve: {
    alias: {
      moment: "moment/src/moment"
    }
  },
  module: {
    rules: [
      {
        test: /.jsx?$/,
        loader: "babel-loader",
        exclude: /node_modules/,
        query: {
          presets: ["@babel/preset-env", "env", "react", "stage-2"]
        }
      },
      {
        loader: "babel-loader",
        exclude: /node_modules/,
        test: /\.js$/,
        options: {
          presets: ["@babel/preset-env", "env", "react", "stage-2"],
          plugins: [
            [
              "import",
              {
                libraryName: "antd",
                style: true
              }
            ]
          ]
        }
      }
    ]
  },
  devServer: {
    port: 8000,
    contentBase: "dist"
  }
};

如何解决此问题?

0 个答案:

没有答案