簡體   English   中英

模塊構建失敗 - 錯誤:找不到模塊(Babel & Rails 6)

[英]Module Build Failed - Error: Cannot find module (Babel & Rails 6)

Rails 初學者在這里和第一次海報。 遇到這個破壞我的 JS 的控制台錯誤:非常感謝任何幫助!!:

控制台錯誤

未捕獲的錯誤:模塊構建失敗(來自./node_modules/babel-loader/lib/index.js):錯誤:找不到模塊'/Users/cameron/Documents/Rails Projects/main/rsvp_new/node_modules/@babel/compat-數據/數據/corejs3-shipped-proposals.json'

.babelrc

{
  "presets": [
    "airbnb"
  ],
  "plugins": [
    "add-module-exports",
    ["transform-replace-object-assign", { "moduleSpecifier": "object.assign" }],
  ],
}

.package.json

    {
  "name": "rsvp_new",
  "private": true,
  "dependencies": {
    "@babel/polyfill": "^7.12.1",
    "@babel/preset-react": "^7.12.10",
    "@rails/actioncable": "^6.0.0",
    "@rails/activestorage": "^6.0.0",
    "@rails/ujs": "^6.0.0",
    "@rails/webpacker": "^6.0.0-pre.1",
    "@zxing/library": "^0.18.3",
    "babel": "^6.23.0",
    "babel-preset-env": "^1.7.0",
    "bootstrap": "^4.5.3",
    "jquery": "^3.5.1",
    "popper.js": "^1.16.1",
    "turbolinks": "^5.2.0"
  },
  "version": "0.1.0",
  "devDependencies": {
    "@babel/core": "^7.12.10",
    "@babel/preset-env": "^7.12.11",
    "babel-loader": "^8.2.2",
    "babel-preset-react": "^6.24.1",
    "webpack": "^4.44.2",
    "webpack-dev-server": "^3.11.0"
  }
}

babel.config.js

module.exports = function(api) {
  var validEnv = ['development', 'test', 'production']
  var currentEnv = api.env()
  var isDevelopmentEnv = api.env('development')
  var isProductionEnv = api.env('production')
  var isTestEnv = api.env('test')

  if (!validEnv.includes(currentEnv)) {
    throw new Error(
      'Please specify a valid `NODE_ENV` or ' +
        '`BABEL_ENV` environment variables. Valid values are "development", ' +
        '"test", and "production". Instead, received: ' +
        JSON.stringify(currentEnv) +
        '.'
    )
  }

  return {
    presets: [
      isTestEnv && [
        '@babel/preset-env',
        {
          targets: {
            node: 'current'
          }
        }
      ],
      (isProductionEnv || isDevelopmentEnv) && [
        '@babel/preset-env',
        {
          forceAllTransforms: true,
          useBuiltIns: 'entry',
          corejs: 3,
          modules: false,
          exclude: ['transform-typeof-symbol']
        }
      ]
    ].filter(Boolean),
    plugins: [
      'babel-plugin-macros',
      '@babel/plugin-syntax-dynamic-import',
      isTestEnv && 'babel-plugin-dynamic-import-node',
      '@babel/plugin-transform-destructuring',
      [
        '@babel/plugin-proposal-class-properties',
        {
          loose: true
        }
      ],
      [
        '@babel/plugin-proposal-object-rest-spread',
        {
          useBuiltIns: true
        }
      ],
      [
        '@babel/plugin-transform-runtime',
        {
          helpers: false,
          regenerator: true,
          corejs: false
        }
      ],
      [
        '@babel/plugin-transform-regenerator',
        {
          async: false
        }
      ]
    ].filter(Boolean)
  }
}

設法解決了它,盡管這仍然是一個謎。

我首先使用git checkout並返回到較早的提交以查看錯誤是否仍然存在。 謝天謝地,錯誤消失了。 然后我返回到我最近的提交,錯誤似乎已經解決。

很抱歉,這個答案沒有什么幫助。 但是,如果對遇到此問題的任何人有任何建議,請重新訪問您認為錯誤沒有持續存在的早期提交,並查看該錯誤是否仍然出現在控制台中。

如果我發現任何進一步的信息,將發布更多關於此的信息。

你試過這個嗎

npm install @babel/compat-data

有同樣的錯誤,只是添加了 package:

yarn add babel-plugin-macros

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM