-
Notifications
You must be signed in to change notification settings - Fork 25
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
TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING] #55
Comments
cc/ @giltayar -- I imagine we don't support loading fake JSON via ESM? |
Originally, I'm not mocking a json file, I'm just importing a JSON file outside of one of our unit tests, and somehow only on Github CI I receive this error. I couldn't replicate this issue on our local machine. |
This has nothing to do with This is by design, as TC39 didn't want to open this to JSON for security reasons. They fixed this security problem by a new feature in JS that allows you to assert that you want a JSON. This new JS feature is implemented in Node v17: https://nodejs.org/dist/latest-v17.x/docs/api/esm.html#import-assertions. A good workaround for this (till you start using Node >= 17) would be to use |
Hi Giltayar, By default quibble assumes are imported giles are modules. The pull request I've opened properly sets the format for a json "module", and instead of just returns it as a module with a export default it just returns a stringified json. Previously, the way quibble handled JSON "modules" was just wrong, even though it kind of works. |
Hi Giltayar, By default quibble assumes are imported files are modules. The pull request I've opened properly sets the format for a json "module", and instead of just returns it as a module with a export default it just returns a stringified json. Previously, the way quibble handled JSON "modules" was just wrong, even though it kind of worked. |
@anonrig I'm not sure you understood what I said above. I just tried importing a JSON in regular Node.js (sans As you can see from the screenshot it doesn't work in Node.js. So why should we make it work with |
The title of this issue is different from the error message you've provided. |
With the latest changes in Node.js 17.1.0, Node disables import of JSON modules without using an assertion. This pull request uses JSON assertion, and therefore handles 17.1.0 For more information about JSON assertions please look into nodejs/node#40250 |
I just tried this code in the current quibble: import quibble from 'quibble'
await quibble.esm('./package.json', undefined, {version: 'worked!'})
console.log((await import('./package.json', {assert: {type: 'json'}})).default.version) And it output This means that |
Using the following code on quibble fails
The text was updated successfully, but these errors were encountered: