Webpack编译:部署生产时找不到模块“ @ babel / preset-env”

时间:2019-12-16 08:03:34

标签: ruby-on-rails deployment capistrano webpacker react-rails

我使用capistrano部署我的Rails项目(Rails 6.0.0,Ruby 2.6.0)

启动`bundle exec cap生产部署时,我得到下面的日志

  

./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'

但是当我在本地0中进行测试时。建立成功

我的 package.json

RAILS_ENV=production bundle exec rails assets:precompile

我的 app / javascript / packs / application.js

{
  "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 / server_rendering.js

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

有什么解决办法吗?谢谢

1 个答案:

答案 0 :(得分:0)

在生产模式下编译时,任何您想使用的内容都必须位于<ScrollView>中。将dependencies@babel/preset-env中移到package.json中的devDependencies中。您也可以删除dependencies,因为这是多余的。