Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@types/node | undici-types] UnsupportedSyntaxError: ImportEquals should have a literal source. #314

Open
1 of 3 tasks
kravetsone opened this issue Jul 17, 2024 · 2 comments

Comments

@kravetsone
Copy link

Checklist

  • I can reproduce this issue when running this plugin on its own.
    Other plugins, such as node-resolve are known to cause issues.
  • I am running this plugin on .d.ts files generated by TypeScript.
    The plugin can consume .ts and even .js files (with allowJs: true), but this is known to cause issues.
  • This issue is not related to rolling up @types.
    The plugin ignores these by default, unless respectExternal is set. @types can contain hand-crafted code which is known to cause issues.

Code Snipped

import type { Response } from "undici-types";

export type A = Response;

Error Message

UnsupportedSyntaxError: ImportEquals should have a literal source.

4:1: `import MockDispatch = MockInterceptor.MockDispatch;`   
    at dr.convertImportDeclaration (Z:\PROJECTS\node-ts\test\node_modules\pkgroll\dist\rollup-plugin-dts-BzOer96X.js:27:10590)
    at dr.convertStatement (Z:\PROJECTS\node-ts\test\node_modules\pkgroll\dist\rollup-plugin-dts-BzOer96X.js:27:8366)     
    at new Transformer (Z:\PROJECTS\node-ts\test\node_modules\pkgroll\dist\rollup-plugin-dts-BzOer96X.js:27:7064)
    at convert (Z:\PROJECTS\node-ts\test\node_modules\pkgroll\dist\rollup-plugin-dts-BzOer96X.js:27:6881)
    at Object.transform (Z:\PROJECTS\node-ts\test\node_modules\pkgroll\dist\rollup-plugin-dts-BzOer96X.js:27:14853)       
    at handleDtsFile (Z:\PROJECTS\node-ts\test\node_modules\pkgroll\dist\rollup-plugin-dts-BzOer96X.js:30:1244)
    at Object.transform (Z:\PROJECTS\node-ts\test\node_modules\pkgroll\dist\rollup-plugin-dts-BzOer96X.js:30:1843)        
    at Z:\PROJECTS\node-ts\test\node_modules\rollup\dist\shared\rollup.js:989:40 {
  code: 'PLUGIN_ERROR',
  plugin: 'dts',
  hook: 'transform',
  id: 'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\mock-agent.d.ts',
  watchFiles: [
    'Z:\\PROJECTS\\node-ts\\test\\src\\index.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\index.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\cache.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\filereader.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\file.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\formdata.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\fetch.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\mock-errors.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\mock-agent.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\mock-pool.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\mock-client.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\api.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\global-dispatcher.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\agent.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\errors.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\connector.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\client.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\balanced-pool.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\interceptors.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\handlers.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\pool.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\dispatcher.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\global-origin.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\proxy-agent.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\cookies.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\diagnostics-channel.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\websocket.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\content-type.d.ts',
    'Z:\\PROJECTS\\node-ts\\test\\node_modules\\undici-types\\mock-interceptor.d.ts'
  ]
}

undici-types used by @types/node and in dependencies source code it looks like import("undici-types").Response

@kravetsone
Copy link
Author

still occured(

@kravetsone
Copy link
Author

as a workaraound for:

const response = new Response("ok"); // error ar build time like in issue

u can cast it type to Response and idk why it solve the issue

const response = new Response("ok") as Response; // no error at build time

kravetsone added a commit to gramiojs/gramio that referenced this issue Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant