您当前的位置: 首页 > 

彭世瑜

暂无认证

  • 3浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

ReferenceError: self is not defined

彭世瑜 发布时间:2022-05-16 22:52:53 ,浏览量:3

使用webpack打包库文件后,在node端执行引入报错

ReferenceError: self is not defined

解决办法:

module.exports = {
  output: {
    globalObject: 'this'
  }
}

完整配置

const path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'more-echo.js',
    globalObject: 'this',
    library: {
      name: 'moreEcho',
      type: 'umd',
    },
  },
};

依赖版本

{
  "devDependencies": {
    "webpack": "^5.72.1",
    "webpack-cli": "^4.9.2"
  }
}

参考

  1. https://github.com/webpack/webpack/issues/6784
  2. https://webpack.js.org/configuration/output/#outputglobalobject
关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.1546s