ReferenceError: self is not defined

简介: ReferenceError: self is not defined

使用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"
  }
}
相关文章
|
开发者
SyntaxError: cannot assign to literal错误
SyntaxError: cannot assign to literal错误
2166 1
成功解决:Error in created hook: “ReferenceError: params is not defined“
该博客文章描述了作者解决"ReferenceError: params is not defined"错误的过程,原因是路由传递的params参数与调用方法中的参数名称冲突,最终通过检查接口参数解决了问题。
成功解决:Error in created hook: “ReferenceError: params is not defined“
|
3月前
|
小程序 定位技术
__g is not defined
这篇文章通过分享经典电影对白和英文版的《小情歌》来唤起读者的独家记忆,但具体内容未提及,只展示了一些图片。
|
6月前
|
前端开发
使用ffmpeg-core的时候报错,解决Uncaught (in promise) ReferenceError: SharedArrayBuffer is not defined
使用ffmpeg-core的时候报错,解决Uncaught (in promise) ReferenceError: SharedArrayBuffer is not defined
|
12月前
|
小程序 开发者
小程序报错-ReferenceError: regeneratorRuntime is not defined
小程序报错-ReferenceError: regeneratorRuntime is not defined
111 0
|
12月前
ReferenceError: document is not defined
ReferenceError: document is not defined
50 0
|
12月前
ReferenceError: _dirname is not defined
ReferenceError: _dirname is not defined
70 0
|
JavaScript CDN
Uncaught TypeError: Cannot redefine property: $router
Uncaught TypeError: Cannot redefine property: $router
177 0
|
内存技术
|
Dart 前端开发 JavaScript
Syntax Error: TypeError: this.getOptions is not a function
Syntax Error: TypeError: this.getOptions is not a function
526 0
Syntax Error: TypeError: this.getOptions is not a function