无法使用babel和webapck读取未定义的属性"helpers" [英] Cannot read property 'helpers' of undefined with babel and webapck

查看:146
本文介绍了无法使用babel和webapck读取未定义的属性"helpers"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建Safari扩展.由于无法在浏览器中使用requireimport,因此尝试设置Webpack和Babel.我对发现的其他一些例子作出了很大的回应,但没有喜悦.任何帮助表示赞赏.

I'm trying to build a Safari extension. Since I can't use require or import in the browser, I am trying to set up Webpack and Babel. I replied heavily on some other examples I found, but no joy. Any help appreciated.

webpack.conf.js

const path = require('path')

module.exports = {
    target: 'web',
    entry: './src/index.js',
    output: {
        path: path.resolve(__dirname, "ReduxDevTools.safariextension"),
        filename: 'index.js'
    },
    module: {
      rules: [
        {
          test: /src\/.+\.js$/,
          exclude: /(node_modules|ReduxDevTools\.safariextension)/,
          use: {
            loader: 'babel-loader',
            options: {
              "presets": [
                ["@babel/preset-env", {
                  "targets": {
                    "safari": 10
                  }
                }],
                "@babel/preset-stage-0"
              ],
              "plugins": [
                ["@babel/plugin-transform-runtime", {
                  "helpers": false,
                  "polyfill": false,
                  "regenerator": true,
                  "moduleName": "@babel/runtime"
                }]
              ]
            }
          }
        }
      ]
    }
}

package.json

"scripts": {
    "build": "./node_modules/.bin/webpack",
    "dev": "nodemon --watch ./src --exec yarn run build"
  },

目录

├── CertificateSigningRequest.certSigningRequest
├── ReduxDevTools.safariextension
│   ├── AppIcon.appiconset
│   │   ├── Contents.json
│   │   ├── logo-2-1024.png
│   │   ├── logo-2-128.png
│   │   ├── logo-2-16.png
│   │   ├── logo-2-256.png
│   │   ├── logo-2-32.png
│   │   ├── logo-2-512.png
│   │   └── logo-2-64.png
│   ├── Info.plist
│   ├── Settings.plist
│   ├── index.html
│   └── index.js
├── dist
├── package.json
├── src
│   └── index.js
├── webpack.config.js
├── yarn-error.log
└── yarn.lock

错误

[nodemon] starting `yarn run build`
warning ../package.json: No license field
$ ./node_modules/.bin/webpack
Hash: e42a920b430f30cdd9f4
Version: webpack 3.10.0
Time: 1637ms
   Asset     Size  Chunks             Chunk Names
index.js  4.08 kB       0  [emitted]  main
   [0] ./src/index.js 1.61 kB {0} [built] [failed] [1 error]

ERROR in ./src/index.js
Module build failed: TypeError: Cannot read property 'helpers' of undefined
    at _default (/Users/noah/Projects/ReduxDevtoolsExtension/node_modules/@babel/plugin-transform-runtime/lib/index.js:17:25)
    at Function.memoisePluginContainer (/Users/noah/Projects/node_modules/babel-core/lib/transformation/file/options/option-manager.js:113:13)
    at Function.normalisePlugin (/Users/noah/Projects/node_modules/babel-core/lib/transformation/file/options/option-manager.js:146:32)
    at /Users/noah/Projects/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
    at Array.map (<anonymous>)
    at Function.normalisePlugins (/Users/noah/Projects/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
    at OptionManager.mergeOptions (/Users/noah/Projects/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
    at OptionManager.init (/Users/noah/Projects/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at File.initOptions (/Users/noah/Projects/node_modules/babel-core/lib/transformation/file/index.js:212:65)
    at new File (/Users/noah/Projects/node_modules/babel-core/lib/transformation/file/index.js:135:24)
    at Pipeline.transform (/Users/noah/Projects/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
    at transpile (/Users/noah/Projects/ReduxDevtoolsExtension/node_modules/babel-loader/lib/index.js:50:20)
    at Object.module.exports (/Users/noah/Projects/ReduxDevtoolsExtension/node_modules/babel-loader/lib/index.js:175:20)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[nodemon] app crashed - waiting for file changes before starting...

推荐答案

如果使用的是自动安装的babel-loader@7@babel/core beta,请尝试使用babel-loader@^8.0.0-beta.0.

If you're using babel-loader@7, which is what is automatically installed, along with @babel/core beta, try use babel-loader@^8.0.0-beta.0.

yarn add --dev babel-loader@^8.0.0-beta.0

这篇关于无法使用babel和webapck读取未定义的属性"helpers"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆