Closed rubensworks closed 2 years ago
I'm getting Cannot find module path/to/my/project/node_modules/typeorm/package.json.js
when running componentsjs-generator
on my project.
The typeorm
package has this as its exports
in package.json
:
"exports": {
".": {
"types": "./index.d.ts",
"node": {
"import": "./index.mjs",
"require": "./index.js",
"types": "./index.d.ts"
},
"browser": {
"require": "./index.js",
"import": "./browser/index.js",
"default": "./index.js"
}
},
"./browser": {
"types": "./index.d.ts",
"default": "./browser/index.js"
},
"./*.js": "./*.js",
"./*": {
"require": "./*.js",
"import": "./*"
}
}
If I add "./package.json": "./package.json",
to the top of the exports
the problem is fixed as found here https://github.com/typeorm/typeorm/issues/9178
I'm on componentsjs-generator
version 2.6.1
@adlerfaulkner A workaround for such broken packages is being worked in here: https://github.com/LinkedSoftwareDependencies/Components-Generator.js/issues/95
When importing from packages without
main
entrypoint, such as TS types packages like@rdfjs/types
, then the generator will fail with an error:Cannot find module @rdfjs/types
This is because the
require.resolve
logic depends on thismain
entrypoint.We might have to dive into the codebase of
tsc
to see how they resolve this problem there. But likely, we'll have to reimplement (parts of)require.resolve
ourselves to be able to cope with these kinds of resolutions.