Is it possible to import a mix of CommonJS-only deps and ESM-only deps? #1560
-
Hello! Please forgive my lack of understanding/clarity in this post, hopefully it makes sense, so what I am trying to do is:
I want to do both in the same {
"compilerOptions": {
"target": "es5",
"lib": ["dom", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"plugins": [{ "name": "typescript-plugin-css-modules" }]
},
"include": ["src/**/*", "scripts/**/*"],
"exclude": ["node_modules"],
"ts-node": {
"compilerOptions": {
"module": "CommonJS"
}
}
} This is the file that I am trying to run: import fs from 'fs/promises';
import path from 'path';
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkGfm from 'remark-gfm';
import remarkRehype from 'remark-rehype';
import rehypeStringify from 'rehype-stringify';
/// the rest of the file... I'm going to run it with First attempt
Second attemptAfter reading some issues, I take it that
Well, the error changes. It would appear that Node doesn't understand Third attempt
Are there any other options? Other things that I have tried:
All 3 didn't do the trick... if you have some experiences regarding this kind of thing, I will really appreciate it if you could share your thoughts. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Nevermind, turns out I needed to also include the |
Beta Was this translation helpful? Give feedback.
Nevermind, turns out I needed to also include the
.js
extensions when importing: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#im-having-problems-with-esm-and-typescript. Closing this.