Fix ES module build of rollup plugin #12

Closed
hanneskuettner wants to merge 1 commit from fix/es-module into main
hanneskuettner commented 2023-02-28 15:28:32 +01:00 (Migrated from github.com)

This commit fixes issue lezer-parser/lezer#30.

The problem is that the generated rollup plugin imported buildParserFile from the parent directory index. This is not allowed in ES modules as file extensions are mandatory. A solution was to use the --experimental-specifier-resolution=node flag with node, for which support was dropped in Node v19. This issue resurfaced for me while trying to use the plugin with the most recent version of vite.

#9 tried fixing the issue, by simply importing the index.ts file. Problem there was that all dependencies were marked external in the rollup config, resulting in the import being copied verbatim and a broken rollup plugin.

Here we change the relative import to an import of the @lezer/generator package.
(I considered using ./index.js since that is the ES module output file, but that I presume would break when using the cjs artifacts, since the import is not touched by rollup and not rewritten to the, then correct index.cjs.)

This commit fixes issue [lezer-parser/lezer#30](https://github.com/lezer-parser/lezer/issues/30). The problem is that the generated rollup plugin imported `buildParserFile` from the parent directory index. This is [not allowed in ES modules](https://nodejs.org/api/esm.html#mandatory-file-extensions) as file extensions are mandatory. A solution was to use the `--experimental-specifier-resolution=node` flag with node, for which support was dropped in Node v19. This issue resurfaced for me while trying to use the plugin with the most recent version of `vite`. #9 tried fixing the issue, by simply importing the `index.ts` file. Problem there was that all dependencies were marked external in the rollup config, resulting in the import being copied verbatim and a broken rollup plugin. Here we change the relative import to an import of the `@lezer/generator` package. (I considered using `./index.js` since that is the ES module output file, but that I presume would break when using the cjs artifacts, since the import is not touched by rollup and not rewritten to the, then correct `index.cjs`.)
marijnh commented 2023-02-28 15:46:24 +01:00 (Migrated from github.com)

There is no guarantee that @lezer/generator is going to point at the package itself. If you, for example, check out that package on its own, it won't be able to resolve this.

There is no guarantee that `@lezer/generator` is going to point at the package itself. If you, for example, check out that package on its own, it won't be able to resolve this.

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/generator!12
No description provided.