Generate declarations as index.d.ts instead of highlight.d.ts #1

Closed
fonsp wants to merge 1 commit from index-d-ts into main
fonsp commented 2022-05-18 13:45:32 +02:00 (Migrated from github.com)

I was having trouble building declarations for my project, with the following error:

➜  codemirror-pluto-setup git:(codemirror-0.20.0-but-better) ✗ npm run bundle

> @plutojl/codemirror-pluto-setup@0.28.0 bundle
> rollup -c


src/basic-setup.ts → dist/index.es.js...
created dist/index.es.js in 1.3s

src/basic-setup.ts → dist/index.d.ts...
[!] Error: 'Highlighter' is not exported by node_modules/@lezer/highlight/dist/index.js, imported by node_modules/@codemirror/language/dist/index.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
node_modules/@codemirror/language/dist/index.js
Error: 'Highlighter' is not exported by node_modules/@lezer/highlight/dist/index.js, imported by node_modules/@codemirror/language/dist/index.js
    at error (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:198:30)
    at Module.error (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:12477:16)
    at Module.traceVariable (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:12835:29)
    at ModuleScope.findVariable (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:11465:39)
    at FunctionScope.findVariable (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:6433:38)
    at Identifier.bind (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:7724:40)
    at AssignmentPattern.bind (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:5298:23)
    at FunctionDeclaration.bind (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:5294:31)
    at Program.bind (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:5294:31)
    at Module.bindReferences (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:12473:18)

(I am using @codemirror/language@0.20.1 and @lezer/highlight@0.16.0.)

I am getting this error because the declarations for @lezer/highlight/dist/index.js are in @lezer/highlight/dist/highlight.d.ts, not @lezer/highlight/dist/index.d.ts, and it looks like my bundler expects the declarations to have the same name as the JS file.

This PR fixes it by renaming src/highlight.ts to src/index.ts, which will rename the .d.ts file. (I could not find a way to change the name of the declarations file using config alone).

I was having trouble building declarations for my project, with the following error: ``` ➜ codemirror-pluto-setup git:(codemirror-0.20.0-but-better) ✗ npm run bundle > @plutojl/codemirror-pluto-setup@0.28.0 bundle > rollup -c src/basic-setup.ts → dist/index.es.js... created dist/index.es.js in 1.3s src/basic-setup.ts → dist/index.d.ts... [!] Error: 'Highlighter' is not exported by node_modules/@lezer/highlight/dist/index.js, imported by node_modules/@codemirror/language/dist/index.js https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module node_modules/@codemirror/language/dist/index.js Error: 'Highlighter' is not exported by node_modules/@lezer/highlight/dist/index.js, imported by node_modules/@codemirror/language/dist/index.js at error (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:198:30) at Module.error (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:12477:16) at Module.traceVariable (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:12835:29) at ModuleScope.findVariable (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:11465:39) at FunctionScope.findVariable (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:6433:38) at Identifier.bind (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:7724:40) at AssignmentPattern.bind (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:5298:23) at FunctionDeclaration.bind (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:5294:31) at Program.bind (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:5294:31) at Module.bindReferences (/Users/fons/Documents/codemirror-pluto-setup/node_modules/rollup/dist/shared/rollup.js:12473:18) ``` (I am using [@codemirror/language@0.20.1](https://cdn.jsdelivr.net/npm/@codemirror/language@0.20.1/) and [@lezer/highlight@0.16.0](https://cdn.jsdelivr.net/npm/@lezer/highlight@0.16.0/).) I am getting this error because the declarations for `@lezer/highlight/dist/index.js` are in `@lezer/highlight/dist/highlight.d.ts`, not `@lezer/highlight/dist/index.d.ts`, and it looks like my bundler expects the declarations to have the same name as the JS file. This PR fixes it by renaming `src/highlight.ts` to `src/index.ts`, which will rename the `.d.ts` file. (I could not find a way to change the name of the declarations file using config alone).
marijnh commented 2022-05-18 14:31:05 +02:00 (Migrated from github.com)

and it looks like my bundler expects the declarations to have the same name as the JS file.

Seems it is ignoring the types field in package.json, which sounds like an issue in the bundler. I generally don't accept patches that work around bugs in other software, since those are really not my responsibility.

> and it looks like my bundler expects the declarations to have the same name as the JS file. Seems it is ignoring the `types` field in package.json, which sounds like an issue in the bundler. I generally don't accept patches that work around bugs in other software, since those are really not my responsibility.
fonsp commented 2022-05-18 17:45:40 +02:00 (Migrated from github.com)

Alright, sounds fair!

Alright, sounds fair!

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/highlight!1
No description provided.