-
Notifications
You must be signed in to change notification settings - Fork 109
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
Dependency with type: module
loads module as unevaluated text contents of main
field
#491
Comments
I have the same issue when importing idb https://github.com/jakearchibald/idb/blob/main/package.json and in my case I'm not able to fix it with @thw0rted did you add that in package.json? |
Sorry @rinick , I actually wound up being unable to use this package and went back to It's been a few months since I looked at this, but IIRC the issue that killed me was Angular support. It might have been that I couldn't get Anyway, your issue is slightly different from mine. It might help illustrate your problem if you can put together a minimal reproduction? (Also might help track down how/why this is happening in the first place...) |
@thw0rted thanks for the reply. |
You can certainly consider it, but if karma-ts works for you other than this one little issue, it's probably worth trying to stick with it. I believe with karma-webpack, you basically have webpack watching your files to make new builds, then Karma watching the webpack build to run new tests, while with karma-typescript you have karma watching the code more or less directly (with a transpiler in the middle). I don't have a big non-Angular project set up to do a side by side test, but I was trying to migrate from karma-webpack to karma-typescript because the former seems especially slow. |
Hi there, I am also running into this issue but for a different dependency. What is the ideal fix to solve this issue - what specifically would need implemented in karma-typescript? |
@thw0rted I've faced this problem too with the fflate package. Here is a small reproducible demo: karma-typescript-491.zip (unpack the directory and run The problem can be fixed by changing this karma-typescript line: public isScript(): boolean {
- return (this.filename && !this.isTypingsFile() && /\.(js|jsx|mjs|ts|tsx)$/.test(this.filename))
+ return (this.filename && !this.isTypingsFile() && /\.(js|jsx|mjs|cjs|ts|tsx)$/.test(this.filename))
|| this.transformedScript;
} I don't make a PR because I'm not sure that this is a proper solution. My current workaround to make {
// ...
karmaTypescriptConfig: {
// ...
bundlerOptions: {
exclude: ['worker_threads'],
resolve: {
alias: {
fflate: 'node_modules/fflate/umd/index.js',
},
},
},
},
} |
Repro here
I use the
cesium
library. It's written in vanilla ES6 JS, and they build a CJS version (two, actually, minified and unminified) to include in the NPM package as well. Their package.json file includesWhen I
import { JulianDate } from "cesium"
, the imported object isundefined
. Stepping through the debug test runner, I see that the transpiledrequire("cesium")
call returns the literal text contents of index.cjs as a string, so of course theJulianDate
property of that "module" is undefined.In the short term I'm able to work around this with
In the long run, I think you're going to see more packages shipping both ESM and CJS distros, and using
package.json
fields to provide the appropriate module type, so I figured I should report it.The text was updated successfully, but these errors were encountered: