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

[Bug]: "SyntaxError: Unexpected token 'with'" error when using import assertions (ESM) #14345

Closed
pablomarquezcabify opened this issue Jul 20, 2023 · 3 comments

Comments

@pablomarquezcabify
Copy link

Version

29.6.1

Steps to reproduce

  1. Clone this repo
  2. Run npm install and npm test

Expected behavior

Runs test

Actual behavior

Returns the follwing error:

 SyntaxError: Unexpected token 'with'

      at Runtime.loadEsmModule (node_modules/jest-runtime/build/index.js:510:20)

Additional context

I'm using @babel/plugin-syntax-import-attributes with option deprecatedAssertSyntax so we can still use assert keyword (needed for my project). Babel is transforming it to with keyword.

Environment

System:
    OS: macOS 12.5.1
    CPU: (8) arm64 Apple M2
  Binaries:
    Node: 18.16.1 - ~/.volta/tools/image/node/18.16.1/bin/node
    Yarn: 4.0.0-rc.44 - ~/.volta/tools/image/yarn/4.0.0-rc.44/bin/yarn
    npm: 9.5.1 - ~/.volta/tools/image/node/18.16.1/bin/npm
  npmPackages:
    jest: 29.6.1 => 29.6.1
@mrazauskas
Copy link
Contributor

If Jest config with transform: {} is added to your reproduction repo, the test is passing. Did I miss something? Do you need Babel for some reason?

Your project is written in ESM syntax and you have "type": "module" in package.json. So Jest is executing everything as ESM. There is no need to involve Babel, which is generally used to transform code into CJS. The transform: {} line simply tells to not transform anything. That would not work if you need Babel for some reason.

@pablomarquezcabify
Copy link
Author

Indeed that fixed it 🙌

Now that you're saying, I don't think we need Babel at all at this point. So thanks again for that.

@github-actions
Copy link

github-actions bot commented Sep 4, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants