LinkedSoftwareDependencies / Components-Generator.js

⚙️ Generate Components.js component files from TypeScript
13 stars 7 forks source link

Error on TS type packages #83

Closed rubensworks closed 2 years ago

rubensworks commented 2 years ago

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 this main 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.

adlerfaulkner commented 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

rubensworks commented 2 years ago

@adlerfaulkner A workaround for such broken packages is being worked in here: https://github.com/LinkedSoftwareDependencies/Components-Generator.js/issues/95