remirror / remirror

ProseMirror toolkit for React 🎉
https://remirror.io
MIT License
2.73k stars 237 forks source link

Exports in remirror-extensions are broken (import ... from './_tsup-dts-rollup') after updating to remirror v3 #2287

Open ceisele-r opened 3 months ago

ceisele-r commented 3 months ago

Summary

When upgrading from remirror v2 to v3, exports from remirror-extensions can no longer be resolved correctly:

E.g. the following import

import {
  MentionAtomNodeAttributes,
} from "remirror/extensions";

resolves the import from remirror-extensions.d.ts but inside this file, the export is defined as follows:

export { MentionAtomNodeAttributes } from './_tsup-dts-rollup';

...and ./_tsup-dts-rollup cannot be resolved by Typescript even though there is a _tsup-dts-rollup.d.ts file in the path node_modules\remirror\extensions\dist\

If I (for testing purposes) add the .ts extension to the import in remirror-extensions.d.ts like this:

```typescript
export { MentionAtomNodeAttributes } from './_tsup-dts-rollup.ts';

...we get 1 file further for type resolution. If I then add the .ts extension to the imports in node_modules\@remirror\extension-mention-atom\dist\remirror-extension-mention-atom.d.ts, the type can correctly be resolved.

=> So I guess all imports from './_tsup-dts-rollup'; in all files should instead be from './_tsup-dts-rollup.ts';

Steps to reproduce

See above, try to import

import {
  MentionAtomNodeAttributes,
} from "remirror/extensions";

and see that the type is not correctly resolved.

Expected results

The Types are correctly resolved.

Actual results

See above.

Possible Solution

=> I guess all imports from './_tsup-dts-rollup'; should instead be from './_tsup-dts-rollup.ts';

Screenshot(s)

n/a

ocavue commented 3 months ago

I suspect this issue is related to your tsconfig.json. Could you paste your tsconfig.json here? A minimal reproduction repository would be better.

ceisele-r commented 3 months ago

@ocavue essentially, this is the tsconfig.json using typescript 5.5.4:

{
  "compilerOptions": {
    "incremental": true,
    "tsBuildInfoFile": "./.cache/release.tsbuildinfo",
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "sourceMap": false,
    "rootDir": "./src/",
    "outDir": "./dist/",
    "jsx": "react-jsx",
    "allowJs": true,
    "noEmit": false,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "strictNullChecks": true,
    "strictBindCallApply": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "noUnusedLocals": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strict": true,
    "lib": ["ES2022", "dom"],
    "resolveJsonModule": true,
    "removeComments": true,
    "forceConsistentCasingInFileNames": true,
    "skipLibCheck": true
  },
  "include": ["./src/**/*"],
  "exclude": ["**/webpack.*.js", "**/webpack*.js", "./cypress/**/*"]
}

I can also try if I can create a minimal repro.

ceisele-r commented 3 months ago

I guess changing moduleResolution to Bundler could resolve it according to the docs as this states:

...but unlike the Node.js resolution modes, bundler never requires file extensions on relative paths in imports.

Unfortunately, changing to Bundler is not that easy and probably requires some work on our side before we can validate whether this resolves it.