-
Notifications
You must be signed in to change notification settings - Fork 7
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
bug: fails to load config in ESM project #60
Comments
I'm very keen to support |
For visibility, this is the related upstream PR cosmiconfig/cosmiconfig#283 |
Is there any workaround? |
For not being able to load esm? Can't do much about this until cosmiconfig supports this upstream |
i just create temp module |
with cosmiconfig 8.2.0, ESM is now supported! 🎉 |
it seems that their is a bug. const loadJs: LoaderAsync = async function loadJs(filepath) {
try {
const { href } = pathToFileURL(filepath);
return (await import(href)).default;
} catch (error) {
return loadJsSync(filepath, null);
}
}; return (await import(href)).default; always return
it should be changed to const { href } = pathToFileURL(filepath);
const moduleData = await import(href);
return moduleData.default.|| moduleData; |
consider below example import { defineConfig } from 'vite';
// it is `esm` module causeof type:`module`
export const test = defineConfig({
cake: 'a lie',
}); it will aways return me undefined. |
With esm now supported I'll have to make some changes to support this, PRs welcome but I'll try look at it this week |
This is now in progress, draft PR here https://github.com/Codex-/cosmiconfig-typescript-loader/pull/96 |
Progress can be tracked in #97 |
In any project where
"type": "module"
exists in thepackage.json
, this package crashes when trying to load a config file. The error that appears is similar to:The cause of the issue appears to be with the
require
statement here:cosmiconfig-typescript-loader/lib/loader.ts
Lines 12 to 14 in 37a3004
I can provide a sample repro repo if requested.
related issue: dotansimha/graphql-code-generator-community#225
The text was updated successfully, but these errors were encountered: