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

with node 16 "assert {type: 'json'}" is required but can't be parsed by vitest #1610

Closed
6 tasks done
francois-spectre opened this issue Jul 7, 2022 · 6 comments
Closed
6 tasks done
Labels

Comments

@francois-spectre
Copy link

Describe the bug

With node >= 16.14, importing a json file require to add an assertion like

import pkg from '../package.json'  assert {type: 'json'}

If I don't provide it, I get an error ERR_IMPORT_ASSERTION_TYPE_MISSING
If I provide it, it breaks the vitest run with

Error: Parse failure: Unexpected token (18:33)
Contents of line 18: import pkg from '/package.json'  assert {type: 'json'}

Reproduction

  • try to import a json file with node > 16.14
  • add the json assertion assert {type: 'json'}
  • run the tests

System Info

System:
    OS: macOS 12.2.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 116.70 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
    npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
    Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 103.0.5060.114
    Safari: 15.3
  npmPackages:
    vitest: ^0.17.0 => 0.17.0

Used Package Manager

npm

Validations

@sheremet-va
Copy link
Member

Vitest doesn't parse anything, please follow Vite issue: vitejs/vite#4934

@francois-spectre
Copy link
Author

ok yes thank you for the link to the vite issue.
But it seems that it is merged in vite but still not working with vitest (I have just tried with the last version 0.17.1)

@sheremet-va
Copy link
Member

ok yes thank you for the link to the vite issue.
But it seems that it is merged in vite but still not working with vitest (I have just tried with the last version 0.17.1)

I don't think Vite released a new version with a fix, it was merged 2 days ago. You would also need Vite 3 for this to work

@francois-spectre
Copy link
Author

oh yes so I tried with 3.0.0-beta.7 and it is working! thank you!

@terwer
Copy link

terwer commented Apr 18, 2023

Still not work

Contents of line 125:     const { default: data } = await import(fullJsonPath, { assert: { type: "json" } });

Vitest latest version

"vitest": "^0.30.1"

@terwer
Copy link

terwer commented Apr 18, 2023

Full stack


Error: Parse failure: Unexpected token (195:18)
At file: /src/lib/siyuanDevice.ts
Contents of line 195:       fullJsonPath,
    at ssrTransformScript (file:///Users/terwer/Documents/mydocs/zhi/node_modules/.pnpm/registry.npmjs.org+vite@4.2.2_@types+node@18.15.11/node_modules/vite/dist/node/chunks/dep-d305c21f.js:53410:15)
    at ssrTransform (file:///Users/terwer/Documents/mydocs/zhi/node_modules/.pnpm/registry.npmjs.org+vite@4.2.2_@types+node@18.15.11/node_modules/vite/dist/node/chunks/dep-d305c21f.js:53385:12)
    at Object.ssrTransform (file:///Users/terwer/Documents/mydocs/zhi/node_modules/.pnpm/registry.npmjs.org+vite@4.2.2_@types+node@18.15.11/node_modules/vite/dist/node/chunks/dep-d305c21f.js:62785:20)
    at loadAndTransform (file:///Users/terwer/Documents/mydocs/zhi/node_modules/.pnpm/registry.npmjs.org+vite@4.2.2_@types+node@18.15.11/node_modules/vite/dist/node/chunks/dep-d305c21f.js:41231:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

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

No branches or pull requests

3 participants