It just doesn't work
See original GitHub issueTrying to make your lib work, but have a couple of problems Problem one: internal/modules/cjs/loader.js:1102 throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath); ^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: D:\CODE\node_modules\node-fetch\src\index.js require() of ES modules is not supported. require() of D:\CODE\node_modules\node-fetch\src\index.js from D:\CODE\dist\index.js is an ES module file as it is a .js file whose nearest parent package.json contains “type”: “module” which defines all .js files in that package scope as ES modules. Instead rename D:\CODE\node_modules\node-fetch\src\index.js to end in .cjs, change the requiring code to use import(), or remove “type”: “module” from D:\CODE\node_modules\node-fetch\package.json.
At the end of the log it has some instructions, I followed it but it has another error:
TypeError: (0 , node_fetch_1.default) is not a function
at D:\CODE\dist\index.js:30:34
at Layer.handle [as handle_request] (D:\CODE\node_modules\express\lib\router\layer.js:95:5)
at next (D:\CODE\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (D:\CODE\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (D:\CODE\node_modules\express\lib\router\layer.js:95:5)
at D:\CODE\node_modules\express\lib\router\index.js:281:22
at Function.process_params (D:\CODE\node_modules\express\lib\router\index.js:335:12)
at next (D:\CODE\node_modules\express\lib\router\index.js:275:10)
at D:\CODE\dist\index.js:27:9
at Layer.handle [as handle_request] (D:\CODE\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (D:\CODE\node_modules\express\lib\router\index.js:317:13)
at D:\CODE\node_modules\express\lib\router\index.js:284:7
at Function.process_params (D:\CODE\node_modules\express\lib\router\index.js:335:12)
at next (D:\CODE\node_modules\express\lib\router\index.js:275:10)
at D:\CODE\node_modules\express\lib\router\index.js:635:15
at next (D:\CODE\node_modules\express\lib\router\index.js:260:14)
Reproduction Just trying to fetch with your lib, doesn’t work. You might be interested to hear that I use TS, and I have something called tsc - watch that converts TS code to JS, this might have something to do with the problems above.
Expected behavior It should work.
Hope you can fix this soon.
Issue Analytics
- State:
- Created 2 years ago
- Comments:20 (3 by maintainers)
Top GitHub Comments
@ImperatorOfIntellectualism here is a diff that makes it work for me:
With this both
ts-node
for running the TS files directly andnodemon
on the built files works.--experimental-specifier-resolution=node
is needed because you aren’t specifying a file extension when importing files. That isimport config from './mikro-orm.config'
instead ofimport config from './mikro-orm.config.js'
. I would recommend adding the file extension to the import, since that seems to be what Node.js is recommending going forward.This is the problem… you shouldn’t have to do
'../node_modules/
then you are probably standing in the wrong working directory. Or you haven’t installed the dependency if anything then it should be../node_modules/node-fetch/src/index.js
but you shouldn’t have to do this…i just tried my above suggestion to make sure that it did work, and it did…
also tried sticking the code in a js file and executing
node ./index.js