일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- hardhat
- CSS
- Props
- built in object
- nextJS
- web
- Redux
- graphQL
- solidity
- CLASS
- 기준
- SSR
- node.js
- error
- blockchain
- bitcoin
- middleware
- typeScript
- JavaScript
- Interface
- tailwindcss
- API
- HTML
- Ethereum
- 삶
- concept
- REACT
- evm
- useState
- express.js
- Today
- Total
ReasonJun
Nextjs : Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. (ts-node) 본문
Nextjs : Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. (ts-node)
ReasonJun 2023. 11. 6. 13:50
What happened?
In the case of ts-node, ts was compiled using the commonJS method. Therefore, an error occurs when you try to run a ts file with ts-node in the app or src subfolder of nextjs, which is compiled with esNext.
Error :
https://github.com/TypeStrong/ts-node/issues/935
`ts-node` fails when ES Modules are in the dependency graph in Node.js 13+ · Issue #935 · TypeStrong/ts-node
I basically detailed the issue in this comment: #155 (comment) It's a chicken-and-egg-like problem: If we use module: 'commonjs', then if any TS files import ES Modules (indirectly in their depende...
github.com
Solution :
https://www.npmjs.com/package/ts-node?activeTab=readme#commonjs
ts-node
TypeScript execution environment and REPL for node.js, with source map support. Latest version: 10.9.1, last published: a year ago. Start using ts-node in your project by running `npm i ts-node`. There are 9079 other projects in the npm registry using ts-n
www.npmjs.com
Running a single .ts file in a Next.js project with ts-node for testing
I'm trying to run a single ES module .ts file in a Next.js project with default config for quick debugging: npx ts-node lib/my_module.ts which gives me this error: Warning: To load an ES module, s...
stackoverflow.com