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

Detection for accidentalStrictMode results in failures on some platforms #378

Open
krhougs opened this issue Aug 27, 2019 · 17 comments
Open
Assignees

Comments

@krhougs
Copy link

krhougs commented Aug 27, 2019

Some Javascript runtime like Wechat MiniProgram and Alipay MiniProgram forbids dynamically defining function (related documents), where both Function and eval are undefined.

Recently added detection for accidentalStrictMode used Function as a rescue, which results in failures.

Is there better way to detect accidentalStrictMode or just bypass it?

@aztack
Copy link

aztack commented Jun 8, 2020

Cocos Creator also has forbidden Function and eval.
Introducing regenerator runtime into a Cocos Creator project enables using await/async but prevents projects to be published to the Cocos Play platform.

@shcarrico
Copy link

I am having this same problem; using strict CSP with no unsafe-eval, i end up in the catch block for some reason. I am not entirely clear what is causing me to be in "accidentalStrictMode". Am using the react toolchain based on create-react-app. Am attempting to downgrade this for the time being...

@rbrewington
Copy link

rbrewington commented Jan 13, 2021

I'm having this problem also. I'm working on a healthcare app and allowing unsafe-eval in the CSP is not an option. I can disable strict mode in the rollup options of my library but this seems like a bad workaround. I feel like strict mode should be able to work, and we shouldn't have to give up the performance optimizations and error detection benefits.

@AndrewCraswell
Copy link

AndrewCraswell commented Jan 20, 2021

I think this needs to be revisited. I'm also using toolchains such as create-react-app and tsdx and seeing failures. Both projects are closing issues related to this because they argue it's the problem of regenerator-runtime. Unfortunately our project will fail compliance without a strict CSP, and I'm not sure how to disable strict mode from create-react-app. And as Mozilla noted in regards to this issue, disabling strict mode isn't something anyone is keen to do.

I thought I could resolve the issue by using a yarn resolution to force an older version that doesn't exhibit this issue, but unfortunately that doesn't work either because multiple other libraries we depend on come pre-bundled with a later version of regenerator-runtime. Seems like the only way we will be able to get CSP working is if an update resolves the issue, and libraries start taking in the update. :/

@benjamn benjamn self-assigned this Jan 20, 2021
@benjamn
Copy link
Collaborator

benjamn commented Jan 21, 2021

I recently became aware of a very clever globalThis polyfill that works in all JS implementations, without ever resorting to using the Function constructor: https://mathiasbynens.be/notes/globalthis (by @mathiasbynens).

Here's another project where I implemented this polyfill, and it's worked perfectly so far: apollographql/invariant-packages#53

For historical reasons, I've tried to keep regenerator-runtime/runtime.js runnable as a single script (rather than a CommonJS or ESM module), so I think we would need to inline the https://www.npmjs.com/package/@ungap/global-this implementation, rather than importing it, but it's very short.

Any objections to moving forward with that approach?

@Jack-Works
Copy link

For anyone who struggled with this problem: Run this code before regenerator-runtime executes

globalThis.regeneratorRuntime = undefined

@bwindels
Copy link

bwindels commented Feb 4, 2021

Also hitting this because of the CSP header not allowing unsafe-eval. The globalThis approach indeed seems more practical than disabling strict mode for your entire bundle, which is not the default and thus hard to discover what the actual problem is. It also might make the code run slower by preventing optimizations.

Thanks for providing this great piece of javascript infrastructure in any case!

@mikecann
Copy link

I too am struggling with this issue when building for a chrome extension using esbuild.

Has anyone got a workaround this?

@Jack-Works
Copy link

Yes, @mikecann

You can run this code:

globalThis.regeneratorRuntime = undefined

Before regenerator is loaded.

@mikecann
Copy link

@Jack-Works ye I ended up doing something simmilar thanks to evanw's help: evanw/esbuild#1006 (comment)

@almilo
Copy link

almilo commented Apr 19, 2021

+1

@Ky6uk
Copy link

Ky6uk commented Jul 5, 2021

Does it progress somehow? I've spent tons of time while found this issue because the bug had appeared only on production deployment with strict CSP rules. And still have no idea how to fix it.

I've tried to add an intro banner with window.regeneratorRuntime = undefined (using Vite build tool) and the problem with accidentalStrictMode has gone, but another problem has appeared — third party library is using method regeneratorRuntime.mark(). So mark of undefined is another headache.

@Jack-Works
Copy link

The trick I mentioned only used to define the global variable and the instantiation of the object should be done by the regenerator-runtime. If any of your code runs before the regenerator-runtime I think it's a bundle error

@Ky6uk
Copy link

Ky6uk commented Jul 6, 2021

Yeah, I'm working to find the problem entry point at the moment. Just mentioned accidentalStrictMode failure is super unintuitive and hard to detect the problem as many conditions should be passed at the same time. 😞

@ValerioSevilla
Copy link

Found this issue while trying to load ExcelJS from Salesforce. I have mentioned it in this ExcelJS issue. It seems there is no official solution yet?

daily-autobot pushed a commit to daily-co/daily-js that referenced this issue Jul 18, 2022
…own [regenerator unsafe-eval issue](facebook/regenerator#378). As far as I could tell our code is not relying on `yield` or generator functions (`function*`), so this should be safe. daily-js and the call machine successfully build. I validated that the change in this commit allowed me to remove the `globalThis.regeneratorRuntime = undefined` workaround from our Modern Wordfare demo.
daily-autobot pushed a commit to daily-co/daily-react that referenced this issue Jul 29, 2022
…sform, avoiding the known [regenerator unsafe-eval issue](facebook/regenerator#378). As far as I could tell our code is not relying on `yield` or generator functions (`function*`), so this should be safe.

The build tool TSDX depends on Babel and the problematic transform. Fortunately, TSDX [supports](https://github.com/jaredpalmer/tsdx#babel) specifying a partial `.babelrc` which is automatically merged into its default Babel configuration. I sanity-checked that Babel `'preset-env'` option merging works as expected by adding logging to TSDX.

This is the same fix we already applied to daily-js and the call machine in [this commit](daily-co/pluot-core@a98e54b).
@yoyo930021
Copy link

Fix in #450 ?

@wjpg
Copy link

wjpg commented Dec 26, 2022

Fix in #450 ?

We still needed to set globalThis.regeneratorRuntime = undefined even with the updates in #450

marvinruder added a commit to marvinruder/rating-tracker that referenced this issue Feb 2, 2023
marvinruder added a commit to marvinruder/rating-tracker that referenced this issue Feb 2, 2023
marvinruder added a commit to marvinruder/rating-tracker that referenced this issue Feb 2, 2023
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