nksaraf / vinxi

The Full Stack JavaScript SDK
https://vinxi.vercel.app
MIT License
1.91k stars 77 forks source link

JSON import attributes/assertions break #252

Closed birkskyum closed 6 months ago

birkskyum commented 6 months ago

When importing a .json file, it's required from node 18, 20 to add import assertions/attributes through the use of assert keyword, and from node 21 the with is introduced as well.

I'm using node 18/20, and I have a .json document that I'm trying to import, but I get warnings at dev and build time.

I hit this in solid-start but found I can repro it just with vinxi.

Reproduce 🕹

Stackblitz: https://stackblitz.com/edit/github-ctndfc?file=app%2Fapp.tsx

Error:

1 | import { createSignal } from "solid-js";
2 | import "./app.css";
3 | import dataFile from "./datafile.json" assert {"type":"json"};
  |                                        ^
4 |
5 | export default function App() {
6 |   const [count, setCount] = createSignal(0);
➜ pnpm  run dev

> solid-ssr-basic@ dev /Users/admin/repos/vinxi/examples/solid/ssr/basic
> vinxi dev

vinxi v0.3.10
vinxi starting dev server
(!) Could not auto-determine entry point from rollupOptions or html files and there are no explicit optimizeDeps.include patterns. Skipping dependency pre-bundling.

  ➜ Local:    http://localhost:3000/
  ➜ Network:  use --host to expose

12:03:04 PM [vite] Pre-transform error: /Users/admin/repos/vinxi/examples/solid/ssr/basic/app/app.tsx: Support for the experimental syntax 'importAttributes' isn't currently enabled (4:32):

  2 | import Logo from "./logo.png";
  3 | import "./style.css";
> 4 | import data from "./data.json" assert { "type" : "json"};
    |                                ^
  5 |
  6 | export default function App({ assets, scripts }) {
  7 |   return (

Add @babel/plugin-syntax-import-attributes (https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-import-attributes) to the 'plugins' section of your Babel config to enable parsing.
12:03:04 PM [vite] Error when evaluating SSR module /app/server.tsx: failed to import "/app/app.tsx"
|- SyntaxError: /Users/admin/repos/vinxi/examples/solid/ssr/basic/app/app.tsx: Support for the experimental syntax 'importAttributes' isn't currently enabled (4:32):

I've attempted to install @babel/plugin-syntax-import-attributes through vite-plugin-babel, and .babelrc files to no avail

birkskyum commented 6 months ago

Managed to add the @babel/plugin-syntax-import-attributes inside the app.config