Компиляция Webpack: не удается найти модуль @ babel / preset-env при развертывании производственной среды

я использую capistrano для развертывания моего проекта рельсов (Rails 6.0.0, Ruby 2.6.0)

Я получаю следующий журнал при запуске `bundle exec cap production deploy

ОШИБКА в ./app/javascript/packs/application.js

Ошибка сборки модуля (из ./node_modules/babel-loader/lib/index.js):

Ошибка: не удается найти модуль @ babel / preset-env

а также

ОШИБКА в ./app/javascript/packs/server_rendering.js

Ошибка сборки модуля (из ./node_modules/babel-loader/lib/index.js):

Ошибка: не удается найти модуль @ babel / preset-env

Но когда я тестирую в локальном RAILS_ENV=production bundle exec rails assets:precompile . Он построил успешный

мой package.json

{
  "name": "my_app_name",
  "private": true,
  "dependencies": {
    "@babel/preset-react": "^7.0.0",
    "@rails/actiontext": "^6.0.0",
    "@rails/webpacker": "^4.0.2",
    "axios": "^0.19.0",
    "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
    "core-js": "2",
    "prop-types": "^15.7.2",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react_ujs": "^2.6.0",
    "trix": "^1.0.0",
    "webpack-dev-server": "^3.3.1"
  },
  "devDependencies": {
    "@babel/preset-env": "^7.7.6",
    "babel-preset-env": "^1.7.0",
    "webpack-dev-server": "^3.3.1"
  }
}

мой app / javascript / packs / application.js

// Support component names relative to this directory:
var componentRequireContext = require.context("components", true);
var ReactRailsUJS = require("react_ujs");
ReactRailsUJS.useContext(componentRequireContext);

мой app / javascript / packs / server_rendering.js

// By default, this pack is loaded for server-side rendering.
// It must expose react_ujs as `ReactRailsUJS` and prepare a require context.
var componentRequireContext = require.context("components", true);
var ReactRailsUJS = require("react_ujs");
ReactRailsUJS.useContext(componentRequireContext);

любое решение? Спасибо


person leafeve    schedule 16.12.2019    source источник


Ответы (1)


Все, что вы хотите получить при компиляции в производственном режиме, должно быть в dependencies. Переместите @babel/preset-env из devDependencies в dependencies в package.json. Вы также можете удалить babel-preset-env, поскольку это избыточно.

person rossta    schedule 16.12.2019