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"
  }
}
相关文章
|
6天前
|
前端开发
使用ffmpeg-core的时候报错,解决Uncaught (in promise) ReferenceError: SharedArrayBuffer is not defined
使用ffmpeg-core的时候报错,解决Uncaught (in promise) ReferenceError: SharedArrayBuffer is not defined
|
6月前
|
小程序 开发者
小程序报错-ReferenceError: regeneratorRuntime is not defined
小程序报错-ReferenceError: regeneratorRuntime is not defined
41 0
|
6月前
ReferenceError: document is not defined
ReferenceError: document is not defined
31 0
|
6月前
ReferenceError: _dirname is not defined
ReferenceError: _dirname is not defined
39 0
|
6月前
|
Linux C++
【C++编译】C++ error:‘syscall’ was not declared in this scope
sys/syscall.h 内部表示,他封装了![[Pasted image 20220818151746.png]] 打开对应的 syscall.h 文件内部依旧没有 syscall()函数的声明。
44 0
|
7月前
|
JavaScript CDN
Uncaught TypeError: Cannot redefine property: $router
Uncaught TypeError: Cannot redefine property: $router
55 0
|
内存技术
|
Dart 前端开发 JavaScript
Syntax Error: TypeError: this.getOptions is not a function
Syntax Error: TypeError: this.getOptions is not a function
462 0
Syntax Error: TypeError: this.getOptions is not a function
|
JavaScript
ReferenceError: Cannot access ‘xxx‘ before initialization
ReferenceError: Cannot access ‘xxx‘ before initialization
426 0
ReferenceError: Cannot access ‘xxx‘ before initialization
|
Linux C++
O_RDONLY/O_NOATIME undeclared (first use in this function
O_RDONLY/O_NOATIME undeclared (first use in this function
138 0
O_RDONLY/O_NOATIME undeclared (first use in this function