Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

babel-plugin-istanbul not following CSP directive, Refused to evaluate a string as JavaScript because 'unsafe-eval' #281

Open
praveen7557 opened this issue Feb 13, 2023 · 1 comment

Comments

@praveen7557
Copy link

I am getting the error Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval'" while adding babel-plugin-istanbul to a chrome extension which uses manifest v3 which doesn't allow eval function.

But, the package adds var global = new Function("return this")() to the background.js file. Is there any way to solve this?

@just-toby
Copy link

i'm also having trouble getting this working with my setup.

coverageGlobalScopeFunc: false, coverageGlobalScope: 'window'

setting these options fixes the CSP error, but causes another babel plugin (vanilla-extract) to fail with this error: ReferenceError: window is not defined.

babel-plugin-istanbul seems to be adding instrumentation to my vanilla extract css.ts files. when i exclude these files in the istanbul options, it avoids most of the files, but not all for some reason. this is my setup:

  babel: {
    plugins: [
      [
        'istanbul',
        {
          coverageGlobalScopeFunc: false,
          coverageGlobalScope: 'window',
          'report-dir': 'coverage',
          all: true,
          useInlineSourceMaps: false,
          extends: '@istanbuljs/nyc-config-typescript',
          include: ['src/**/*.tsx', 'src/**/*.ts'],
          exclude: [
            'src/**/*.css',
            'src/**/*.css.ts',
            'src/**/*.test.ts',
            'src/**/*.test.tsx',
            'src/**/*.spec.ts',
            'src/**/*.spec.tsx',
            'src/**/graphql/**/*',
            'src/**/*.d.ts',
          ],
        },
      ],
    ],
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants