wessberg / rollup-plugin-ts

A TypeScript Rollup plugin that bundles declarations, respects Browserslists, and enables seamless integration with transpilers such as babel and swc
MIT License
496 stars 32 forks source link

Deprecated Import Assert in Node.js 22 #228

Open threeal opened 2 months ago

threeal commented 2 months ago

Reproduction

Import rollup-plugin-ts using ESM, either in rollup.config.js or anywhere like this:

import ts from "rollup-plugin-ts";

This issue seems related to https://github.com/rollup/rollup/issues/5531.

Expected Behavior

Should import normally, in the case of Rollup, it should bundle file successfully.

Actual Behavior

When bundle file using Rollup:

[!] SyntaxError: Unexpected identifier 'assert'
    at compileSourceTextModule (node:internal/modules/esm/utils:337:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:166:18)
    at callTranslator (node:internal/modules/esm/loader:436:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:442:30)

When imported in any JavaScript file:

import * as compatData from '@mdn/browser-compat-data' assert { type: 'json' };
                                                       ^^^^^^

SyntaxError: Unexpected identifier 'assert'
    at compileSourceTextModule (node:internal/modules/esm/utils:337:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:166:18)
    at callTranslator (node:internal/modules/esm/loader:436:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:442:30)

Node.js v22.7.0
NullVoxPopuli commented 1 month ago

Looks like it's from here:

❯ ag -u "' assert {" -G ".js$"
node_modules/.pnpm/browserslist-generator@2.3.0/node_modules/browserslist-generator/dist/esm/index.js
3:import * as compatData from '@mdn/browser-compat-data' assert { type: 'json' };
NullVoxPopuli commented 1 month ago

https://github.com/wessberg/browserslist-generator/issues/18