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

Fails test when assert { type: 'json' } is used #1419

Closed
6 tasks done
aMediocreDad opened this issue Jun 3, 2022 · 2 comments
Closed
6 tasks done

Fails test when assert { type: 'json' } is used #1419

aMediocreDad opened this issue Jun 3, 2022 · 2 comments

Comments

@aMediocreDad
Copy link

Describe the bug

I have noticed I cannot use the import type assertions that were included with Node 16.14.2 and onwards.

With Node 16.14.2, JSON import in ESM modules have landed on the same spec as browsers.

import jsonFile from './some-json.json' assert { type: 'json' }

However using this syntax in a test module or any module imported (recursively) by Vitest results in a syntax error.

This is somewhat strange as Vite otherwise bundles files like these without issue.

Reproduction

See an example based on the basic example in this repo: https://github.com/aMediocreDad/vitest-json-assert

Stackblitz cannot be used due to lack of support for LTS node.

System Info

System:
    OS: macOS 12.3.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 433.97 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 18.1.0 - ~/.volta/tools/image/node/18.1.0/bin/node
    npm: 8.9.0 - ~/.volta/tools/image/npm/8.9.0/bin/npm
  Browsers:
    Firefox: 100.0.2
    Safari: 15.4
  npmPackages:
    vite: ^2.9.9 => 2.9.9 
    vitest: latest => 0.13.1

Used Package Manager

npm

Validations

@aMediocreDad
Copy link
Author

Sorry, this is indeed a Vite issue. I am curious as to why it seems to work fine in my project (there is Typescript, Svelte, and Esbuild otherwise involved so could be one of those).

REF vitejs/vite#4934

@sheremet-va
Copy link
Member

It works for you because it is not processed by ssr. Ssr rewrites imports to a custom function, that's why assertions are left out

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

No branches or pull requests

2 participants