-
Notifications
You must be signed in to change notification settings - Fork 10
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
"Cannot use import statement outside a module" while using karma-esbuild #38
Comments
Thanks for filing an issue. It's a bit hard to inspect this further without any code and only seeing the karma config file, so here are some wild guesses you could look into: The module error usually occurs when a script was loaded without the <script src="foo.module.js"></script> <!-- this fails -->
<script src="foo.module.js" type="module"></script> <!-- this is correct for loadding ESM --> By default karma inserts script tags without the files: [
{
pattern: "spec/javascripts/**/*_test.+(js|jsx)",
watched: false,
included: true,
served: true,
// This bit here
type: "module",
},
], Another cause could be a dependency that's not correctly transpiled to non-ESM. The stack trace of the error you're seeing should give hints to that. Another thing you could try is removing the That's all I can think of for now. |
No luck on that but Thank you! I was trying to find where I could apply that attribute via karma. I think our karma version is just way too out of date for that option, I'm going to try to upgrade it. I am a bit confused on why we would need that What code would you like to see? I can try making a repro-repo |
If I had to guess, it's the |
edit: never mind. adding and removing the type: module from the file settings doesn't appear to be doing anything, it is still ultimately failing, but a bit more obtuse now. it's running through some of the tests an eventually will print out this
not sure what that is about, but when I open up the browser and go to the debug html it has a bunch of it gets through about half the tests then fails |
Oh its adding numbers to the end of Exports. so |
Hello there, I'm working on switching my team off of gulp/browserify/babelify and I've gotten some problems worked out of the karma config, but I'm having an issue now where its sending un-esbuild-processed syntax to the browser, or something. It fails on the first test it runs because we are using ESM style import syntax in our file, and I'm unsure why we are getting this in the first place. I know that node and (some) browsers don't support these features, but this was not an issue before, and I thought that esbuild would transpile those away into something else, as it's doing in our main prod build. Any help would be appreciated. here's my karma config.
The text was updated successfully, but these errors were encountered: