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
Is there a way to determine how a module is being imported? #1006
Comments
You should look at the |
Wow @evanw you are quick! Thanks for the suggestion. I have combed through it and tried to use bundle-buddy but its not 100% clear where its coming from. I believe it might be AntD again that is pulling in Heres the meta if you are interested: https://gist.github.com/mikecann/c0908d444fd2b6b56041dff1c7376d5a When I google the error then I come across this post which seems to be talking about the same problem, in that issue he links to the source which has this interesting comment: try {
regeneratorRuntime = runtime;
} catch (accidentalStrictMode) {
// 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.
Function("r", "regeneratorRuntime = r")(runtime);
} I must admit I dont fully understand it but does esbuild enforce "strict mode" when it shouldnt be?! Edit: It appears if the root of the problem is this tho im not exactly sure what to do about it as the "solutions" on there dont seem to work. |
Here's some code to get you started: const fs = require('fs')
const json = JSON.parse(fs.readFileSync('./meta.json', 'utf8'))
function why(what) {
const visited = {}
let found
function search(path, trace) {
if (path === what) {
found = trace.concat(path)
return true
}
if (visited[path]) return
visited[path] = true
const input = json.inputs[path]
for (const imported of Object.values(input.imports))
if (search(imported.path, trace.concat(path)))
return
}
for (const output of Object.values(json.outputs))
if (output.entryPoint && search(output.entryPoint, []))
break
if (found)
console.log(what, 'is included because of', found)
else
console.log(what, 'was not found')
}
why('node_modules/node_modules/regenerator-runtime/runtime.js') That should tell you one of the import paths that is pulling it in. You can modify the code to tell you all import paths instead. |
Awesome thanks @evanw this is what it kicks out:
Which is what I suspected its used by quite a few things but mainly AntD. Because removing AntD is not an option for me I need to try to fix the source of the problem, the CSP violation in regenerator-runtime. As I mentioned in my previous comment it looks like its a known issue in regenerator-runtime, the problem is im not sure what to do about it. I suspect I have to wait until regenerator-runtime fixes the problem. As a work around is it possible to disable "strict mode" in esbuild? |
This isn't possible because esbuild doesn't enable or disable strict mode itself. You can double-check by seeing if your bundle starts with Whether your bundle is run in strict mode or not is up to your JavaScript runtime. For example, loading the bundle with I have no idea how Chrome extensions work, but it's possible they force strict mode too. It's also possible that they aren't run in strict mode but are run in a special environment where you aren't allowed to declare a global variable by assigning to an undeclared variable. That would break this library's strict mode check. One potential workaround to try could be to use esbuild's |
@evanw woooooooooo!! You did it once again mate! banner: {
js: `var regeneratorRuntime;`,
}, Fixes the issue. Not entirely sure either what is causing it, just happy to have a workaround. Massive thanks again for all your hard work and detailed explainations. |
I am in a similar situation as well, but I see things like:
which I believe are using |
Im trying to convert an existing webpack based chrome extension to esbuild.
It builds okay but at runtime I get an error about unsafe-eval:
I think this is because "eval" is not alowd in chrome extensions.
From the stacktrace above line 36793 of background.js is:
So it looks like its coming from regenerator-runtime which is confirmed if I scroll up to the top of the block:
So I think regenerator runtime is being included because of babel, but im not sure why babel would be getting built in?
Is there a way I can work out the chain of dependencies to why babel is being included in the build? Im suspecting a third party library is doing something odd but im not sure how to work out which one..
The text was updated successfully, but these errors were encountered: