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

No useful error provided when importing json array file without @rollup/plugin-json #4635

Closed
hannessolo opened this issue Sep 7, 2022 · 2 comments · Fixed by #4741
Closed

Comments

@hannessolo
Copy link

Rollup Version

^2.78.0

Operating System (or Browser)

MacOS 12.2.1

Node Version (if applicable)

No response

Link To Reproduction

https://stackblitz.com/edit/node-krh8ki?file=README

Expected Behaviour

When requireing a json file, the plugin @rollup/plugin-json is required.

If the plugin is missing, I would expect to get the message Error: Unexpected token (Note that you need @rollup/plugin-json to import JSON files) - as a new user, this is an extremely helpful error message.

Actual Behaviour

When requireing a json file that has an array as the root, and not an object, this error message is not displayed - instead, a much less useful message Error: 'default' is not exported by json-array.json, imported by /home/projects/node-krh8ki/json-array.json?commonjs-proxy is shown.

@lukastaegert
Copy link
Member

An empty array is valid JavaScript, so it is slightly tricky to detect this. But I guess to improve here, it would be sufficient to extend the errors for missing exports with a check if the file extension is .json and then add the same hint to those error messages.
Glad you like the hint we added to the parse error 😉

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4741 as part of rollup@3.7.1. 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