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

Error message for invalid config is misleading #1532

Closed
grimly opened this issue Apr 2, 2021 · 4 comments · Fixed by #1550
Closed

Error message for invalid config is misleading #1532

grimly opened this issue Apr 2, 2021 · 4 comments · Fixed by #1550
Assignees
Labels
Milestone

Comments

@grimly
Copy link
Contributor

grimly commented Apr 2, 2021

Describe the bug

I am using swc with rollup, therefore I am using the API, not the CLI.

I tracked down my issue to the use of the transform function from @swc/core.
I've removed all the code I could to narrow down the source of my problem.

Here is the code to run with node directly :

const { transform } = require('@swc/core');

const filename = 'index.ts';

const code = `
export async function getDependency(): Promise<any> {
  return import('./dep').then(({dependency}) => dependency);
}
`

const options = {
  jsc: {
    parser: {
      syntax: 'typescript',
      dynamicImport: true
    },
    externalHelpers: true,
    target: 'esnext'
  },
  sourceMaps: true,
  filename
}

transform(code, options)
  .then(console.info, console.error)

The following error prints immediately:

error: import(...) expressions requires `jsc.parser.dynamicImport` to be true
 --> index.ts:3:10
  |
3 |   return import('./dep').then(({dependency}) => dependency);
  |          ^^^^^^

The returned promises emits an error which prints as the following:

[Error: failed to process js file

Caused by:
    failed to parse module] {
  code: 'GenericFailure'
}

Expected behavior
The code should compile

Version
The version of @swc/core: 1.2.51

@grimly grimly added the C-bug label Apr 2, 2021
@kdy1
Copy link
Member

kdy1 commented Apr 2, 2021

target: 'esnext' is wrong. You should use target: 'es2020' instead.
Error message seems misleading, though.

@grimly
Copy link
Contributor Author

grimly commented Apr 2, 2021

Indeed this fixed my problem. Thank you very much.

Should I leave this issue open until the error message is clearer or not ?

@kdy1
Copy link
Member

kdy1 commented Apr 2, 2021

Please leave it. I'll change the title.

@kdy1 kdy1 changed the title Failed to transform with dynamicImport option Error message for invalid config is misleading Apr 2, 2021
@kdy1 kdy1 added this to the v1.2.52 milestone Apr 6, 2021
@kdy1 kdy1 mentioned this issue Apr 8, 2021
4 tasks
@kdy1 kdy1 self-assigned this Apr 8, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 8, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 8, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 8, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Apr 8, 2021
@kdy1 kdy1 closed this as completed in #1550 Apr 8, 2021
kdy1 added a commit that referenced this issue Apr 8, 2021
swc:
 - Improve error message for invalid configs. (#1532)

swc_common:
 - Handle input source map correctly. (#1404)

swc_ecma_parser:
 - Fix parsing of generics type declarations when tsx is enabled. (#1526)

swc_ecma_transforms_compat:
 - Allow using carriage return. (#1549)
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 25, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants