Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commonjs plugin is run on typescript definition files #135

@tobiasdiez

Description

@tobiasdiez

Using import type { WithRequired } from '@apollo/utils.withrequired' in a file that is processed with unbuild yields the following error:

Error building /workspaces/apollo-server-integration-h3: SyntaxError: Unexpected token (1:8) in /workspaces/apollo-server-integration-h3/node_modules/.pnpm/@[email protected]/node_modules/@apollo/utils.withrequired/dist/index.d.ts
SyntaxError: Unexpected token (1:8) in /workspaces/apollo-server-integration-h3/node_modules/.pnpm/@[email protected]/node_modules/@apollo/utils.withrequired/dist/index.d.ts
    at pp$4.raise (file:///workspaces/apollo-server-integration-h3/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:19861:13)
    at pp$9.unexpected (file:///workspaces/apollo-server-integration-h3/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:17162:8)
    at pp$9.semicolon (file:///workspaces/apollo-server-integration-h3/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:17139:66)
    at pp$8.parseExpressionStatement (file:///workspaces/apollo-server-integration-h3/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:17622:8)
    at pp$8.parseStatement (file:///workspaces/apollo-server-integration-h3/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:17355:24)
    at pp$8.parseTopLevel (file:///workspaces/apollo-server-integration-h3/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:17219:21)
    at Parser.parse (file:///workspaces/apollo-server-integration-h3/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:16991:15)
    at Function.parse (file:///workspaces/apollo-server-integration-h3/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:17041:35)
    at Graph.contextParse (file:///workspaces/apollo-server-integration-h3/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:23356:38)
    at tryParse (file:///workspaces/apollo-server-integration-h3/node_modules/.pnpm/@[email protected][email protected]/node_modules/@rollup/plugin-commonjs/dist/es/index.js:17:12) {
  pos: 8,
  loc: {
    column: 8,
    file: '/workspaces/apollo-server-integration-h3/node_modules/.pnpm/@[email protected]/node_modules/@apollo/utils.withrequired/dist/index.d.ts',
    line: 1
  },
  raisedAt: 12,
  frame: '1: declare type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;\n' +
    '           ^\n' +
    '2: export = WithRequired;\n' +
    '3: //# sourceMappingURL=index.d.ts.map',
  id: '/workspaces/apollo-server-integration-h3/node_modules/.pnpm/@[email protected]/node_modules/@apollo/utils.withrequired/dist/index.d.ts',
  hook: 'resolveId',
  code: 'PLUGIN_ERROR',
  plugin: 'commonjs--resolver',
  watchFiles: [
    '/workspaces/apollo-server-integration-h3/src/index.ts',
    '/workspaces/apollo-server-integration-h3/node_modules/.pnpm/@[email protected]/node_modules/@apollo/utils.withrequired/dist/index.d.ts'
  ]
}

I think the issue lies in

ctx.options.rollup.commonjs && commonjs({
extensions: DEFAULT_EXTENSIONS,
...ctx.options.rollup.commonjs
}),
, which runs the commonjs also on typescript definition files (and mjs, which seems to be wrong as well).

Reproduction: apollo-server-integrations/apollo-server-integration-h3#12

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdts

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions