Importing ES Modules - Confused about Configuration #2752
Unanswered
kjrocker
asked this question in
Extension Development QnA
Replies: 2 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
1 reply
-
you should ask https://www.npmjs.com/package/@astrojs/compiler to add a separate types file for CommonJS |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to debug ESM imports in my VSCode extension. This started with
import { parse } from "@astrojs/compiler";
, which produced the error:A dynamic import would require restructuring every single function to be async, I really don't want to do that, I just want to use imports normally. The error also suggested setting
type: module
in package.json, but when I do that I, any imports of my own files produces the following:But it's a Typescript file. Adding the ts extension produces:
Updating that setting produces:
I'm now 4 configuration errors deep, and decide this is not the correct path, so I reverse everything.
I also tried, after undoing all that configuration,
const parse = require("@astrojs/compiler").parse
, which no longer threw import errors, but lost the types soparse
was justany
, which was not helpful.I want to import both functions and types from an external library, robustly and simply, in a way that preserves the libraries types.
To duplicate my situation, you can run the following:
npx --package yo --package generator-code -- yo code
I ran into the same issue with
unbundled
, and assumed switching to "esbuild" would configure sensible imports for me. But it didn't help.An example repository is here: https://github.com/kjrocker/import-nightmare
Beta Was this translation helpful? Give feedback.
All reactions