[英]Uncaught ReferenceError: require is not defined at bundle.js(es-build)
I am using an esbuild API build to bundle a basic React app.我正在使用 esbuild API build 来捆绑一个基本的 React 应用程序。 But it keeps bringing up the following error
Uncaught ReferenceError: require is not defined at bundle.js
.Below is my build.js
code.但它不断出现以下错误
Uncaught ReferenceError: require is not defined at bundle.js
。下面是我的build.js
代码。
const esbuild = require('esbuild');
async function build() {
await esbuild.build({
entryPoints: ['index.js'],
outfile: './build/bundle.js',
format: 'cjs',
loader: { '.js': 'jsx' },
});
}
build();
What I tried:我尝试了什么:
bundle.js
and regenerating it againbundle.js
并重新生成它Try to change the scope of require to the scope where you are trying to use it.尝试将 require 的 scope 更改为您尝试使用它的 scope 。
I replaced const esbuild = require('esbuild');
我替换了
const esbuild = require('esbuild');
with import esbuild from 'esbuild';
import esbuild from 'esbuild';
and changed the format to iife.并将格式更改为 iife。 And it worked.
它奏效了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.