Не удалось найти модуль «babel-preset-env» из PATH. Вы имели в виду «@ babel / env»? - PullRequest
0 голосов
/ 14 марта 2020

У меня есть приложение на React с Django сервером, при использовании npm run dev появляется ошибка

Вот полное сообщение об ошибке:
ОШИБКА в ../phonemanager/frontend/src/index.js Сборка модуля не удалась (из ../node_modules/babel-loader/lib/index.js): Ошибка: не удается найти модуль 'babel-preset-env' из 'C: \ Users \ assmy \ OneDrive \ Рабочий стол \ Reaction-redux- django -app' - Вы имели в виду "@ babel / env"? at Function.resolveSyn c [как синхронизация] (C: \ Users \ assmy \ OneDrive \ Рабочий стол \ реагировать-избыточно- django -app \ node_modules \ resol \ lib \ syn c. js : 81: 15) at resolStandardizedName (C: \ Users \ assmy \ OneDrive \ Рабочий стол \ Reaction-redux- django -app \ node_modules@babel \ core \ lib \ config \ files \ plugins. js: 101: 31)
at resolPreset (C: \ Users \ assmy \ OneDrive \ Рабочий стол \ Reaction-redux- django -app \ node_modules@babel \ core \ lib \ config \ files \ plugins. js: 58: 10) в loadPreset (C: \ Users \ assmy \ OneDrive \ Рабочий стол \act-redux- django -app \ node_modules@babel \ core \ lib \ config \ files \ plugins. js : 77: 20) at createDescriptor (C: \ Users \ assmy \ OneDrive \ Рабочий стол \ Reaction-redux- django -app \ node_modules@babel \ core \ lib \ config \ config-descriptors. js: 154: 9) в C: \ Users \ assmy \ OneDrive \ Рабочий стол \act-redux- django -app \ node_modules@babel \ core \ lib \ config \ config-descriptors. js: 109: 50 в Array.map () в createDescriptors (C: \ Users \ assmy \ OneDrive \ Рабочий стол \ реаги-р edux- django -app \ node_modules@babel \ core \ lib \ config \ config-descriptors. js: 109: 29) в createPresetDescriptors (C: \ Users \ assmy \ OneDrive \ Рабочий стол \ реагировать-избыточность - django -app \ node_modules@babel \ core \ lib \ config \ config-descriptors. js: 101: 10)
в C: \ Users \ assmy \ OneDrive \ Рабочий стол \ реагировать-избыточно - django -app \ node_modules@babel \ core \ lib \ config \ config-descriptors. js: 58: 104 в функции cachedFunction (C: \ Users \ assmy \ OneDrive \ Рабочий стол \act-redux- django -app \ node_modules@babel \ core \ lib \ config \ caching. js: 62: 27) по адресу cachedFunction.next (), по запросуvaluSyn c (C: \ Users \ assmy \ OneDrive \ Рабочий стол \ react-redux- django -app \ node_modules \ gensync \ index. js: 244: 28) в синхронизированном режиме c (C: \ Users \ assmy \ OneDrive \ Рабочий стол \ response-redux- django -app \ node_modules \ gensync \ index. js: 84: 14) в пресетах (C: \ Users \ assmy \ OneDrive \ Рабочий стол \ реагировать-редукс- django -app \ node_modules@babel \ core \ lib \ config \ config-descriptors. js: 29: 84) в mergeChainOpts (C: \ Users \ assmy \ OneDr ive \ Рабочий стол \ реагировать-избыточно- django -app \ node_modules@babel \ core \ lib \ config \ config-chain. js: 320: 26) в Function.syn c (C: \ Пользователи \ assmy \ OneDrive \ Рабочий стол \act-redux- django -app \ node_modules \ gensync \ index. js: 84: 14) на объекте. (C: \ Users \ assmy \ OneDrive \ Рабочий стол \act-redux- django -app \ node_modules@babel \ core \ lib \ config \ index. js: 41: 61) в объекте. (C: \ Users \ assmy \ OneDrive \ Рабочий стол \ response-redux- django -app \ node_modules \ babel-loader \ lib \ index. js: 144: 26) в Generator.next () в asyncGeneratorStep (C: \ Users \ assmy \ OneDrive \ Рабочий стол \act-redux- django -app \ node_modules \ babel-loader \ lib \ index. js: 3: 103) в _next (C : \ Users \ assmy \ OneDrive \ Рабочий стол \act-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 () в Object. (C: \ Users \ assmy \ OneDrive \ Рабочий стол \act-redux- django -app \ node_modules \ babel-loader \ lib \ index. js: 5: 97) в Object._loader (C: \ Users \ assmy \ OneDrive \ Рабочий стол \act-redux- django -app \ node_modules \ babel-loader \ lib \ index. js: 224: 18) в Object.loader (C: \ Пользователи \ assmy \ OneDrive \ Рабочий стол \act-redux- django -app \ node_modules \ babel-loader \ lib \ index. js: 60: 18)

пакет. 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"
  }
}

.babelr c:

{
    "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"
  }
};

Как решить эту проблему?

...