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

Remove strict mode for CommonJS build #2

Closed
ntarocco opened this issue May 14, 2020 · 0 comments · Fixed by #3
Closed

Remove strict mode for CommonJS build #2

ntarocco opened this issue May 14, 2020 · 0 comments · Fixed by #3
Labels
bug Something isn't working

Comments

@ntarocco
Copy link
Contributor

When building the CommonJS dist, rollup automatically adds the use strict directive at the beginning of the generated index.js.
Not only this is not needed when CommonJS is exported with modules (see here), but it also breaks JS when Content-Security-Policies is enabled.

Error:

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' ...
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'...

See explanation here

  // This module should not be running in strict mode, so the above
  // assignment should always work unless something is misconfigured. Just
  // in case runtime.js accidentally runs in strict mode, we can escape
  // strict mode using a global Function call. This could conceivably fail
  // if a Content Security Policy forbids using Function, but in that case
  // the proper solution is to fix the accidental strict mode problem. If
  // you've misconfigured your bundler to force strict mode and applied a
  // CSP to forbid Function, and you're not willing to fix either of those
  // problems, please detail your unique predicament in a GitHub issue.

Solution
Change rollup to remove the strict directive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant