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

assert { type: 'json' } results in "Error: Unexpected token" #4530

Closed
cmcculloh opened this issue Jun 16, 2022 · 5 comments · Fixed by #4549
Closed

assert { type: 'json' } results in "Error: Unexpected token" #4530

cmcculloh opened this issue Jun 16, 2022 · 5 comments · Fixed by #4549

Comments

@cmcculloh
Copy link

Rollup Version

2.75.6

Operating System (or Browser)

macOS Monterey

Node Version (if applicable)

16.15.1

Link To Reproduction

https://rollupjs.org/repl/?version=2.75.6&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMGRhdGElMjBmcm9tJTIwJTVDJTIydGVzdC1qc29uLWltcG9ydCUyRmRhdGEuanNvbiU1QyUyMiUyMGFzc2VydCUyMCU3QiUyMHR5cGUlM0ElMjAlNUMlMjJqc29uJTVDJTIyJTIwJTdEJTNCJTVDbiU1Q25jb25zb2xlLnRhYmxlKGRhdGEpJTNCJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlN0QlMkMlN0IlMjJuYW1lJTIyJTNBJTIyZGF0YS5qc29uJTIyJTJDJTIyY29kZSUyMiUzQSUyMiU3QiU1Q24lMjAlMjAlMjAlMjAlNUMlMjJpZCU1QyUyMiUzQSUyMDElNUNuJTdEJTIyJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmVzJTIyJTJDJTIybmFtZSUyMiUzQSUyMm15QnVuZGxlJTIyJTJDJTIyYW1kJTIyJTNBJTdCJTIyaWQlMjIlM0ElMjIlMjIlN0QlMkMlMjJnbG9iYWxzJTIyJTNBJTdCJTdEJTdEJTJDJTIyZXhhbXBsZSUyMiUzQW51bGwlN0Q=

Expected Behaviour

When index.js includes assert { type: 'json'} on an import, and I run yarn rollup index.js it should not error.

This includes both non-npm module json files:

import data from "./data.json" assert { type: "json" };

And those in an npm module:

import data from "test-json-import/data.json" assert { type: "json" };

https://nodejs.org/docs/latest-v16.x/api/esm.html#json-modules

Also see this minimal reproduction repo: https://github.com/cmcculloh/rollup-import-json

Actual Behaviour

Rollup errors on the assert

index.js → stdout...
[!] Error: Unexpected token
index.js (1:61)
1: import data from "./node_modules/test-json-import/data.json" assert { type: "json" };

image

@cmcculloh
Copy link
Author

Just found this plugin which fixes this issue: https://github.com/swiing/rollup-plugin-import-assertions

No idea what your roadmap is like though, whether you want this as a plugin or if it ought to just work in core, so I'll leave this open.

@lukastaegert
Copy link
Member

There is an older issue for the topic: #3799

The plan is definitely to support them eventually. It is just not clear how to do it at the moment, there are some scenarios that need to be cleared up:

  • Will plugins have access to this information in resolveId?
  • Do we actually act on this e.g. by implementing a default handler for 'json'?
  • If such an assertion is on an external dependency, do we emit the assertion in the output?

@lukastaegert
Copy link
Member

Initial support in #4646

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4646 as part of rollup@3.0.0-8. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-8 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4646 as part of rollup@3.0.0. You can test it via npm install rollup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants