2

I am trying to make a chrome extension with esbuild and ts react with a build file that looks something like this.

require('esbuild')
    .build({
        entryPoints: [
            'src/contentScript.ts',
            'src/index.html',
        ],
        outdir: 'dist',
        bundle: true,
        platform: 'browser',
        banner: {
              js: `var regeneratorRuntime;`,
        }
    })
    .catch(() => process.exit(1));

When I build my project, the transpiled code contains the following:

Script.prototype.runInThisContext = function() {
            return eval(this.code);
          }

The use of eval is unacceptable for a chrome extension due to security concerns. So how do I configure esbuild to NOT use eval? I saw a GitHub issue of a similar problem but adding banner: { js: var regeneratorRuntime;, }, did not stop esbuild from using eval. Please help!

sdfsdf
  • 5,052
  • 9
  • 42
  • 75
  • 1
    I'm not sure about esbuild, but in webpack this is a function of the output you choose. Have you already tried different output formats? https://esbuild.github.io/api/#format – Christian Fritz Jul 22 '22 at 14:53
  • 2
    I tried iife, cjs, and esm and all outputs contained eval https://esbuild.github.io/api/#format – sdfsdf Jul 22 '22 at 19:29

0 Answers0