jotai icon indicating copy to clipboard operation
jotai copied to clipboard

Vite 5 / Rollup 4 build warning in v2.6.0

Open Kamahl19 opened this issue 1 year ago • 14 comments

The combination of upgrading to Vite 5 (Rollup 4) and Jotai 2.6.0 results in an error during building

node_modules/jotai/esm/react.mjs (1:0) Error when using sourcemap for reporting an error: Can't resolve original location of error.

This error does not happen in 2.5.1 and also does not happen in Vite 4 + Jotai 2.6.0.

Kamahl19 avatar Nov 25 '23 11:11 Kamahl19

@himself65 Was rollup-plugin-banner2 too easy solution??

dai-shi avatar Nov 25 '23 14:11 dai-shi

@himself65 Was rollup-plugin-banner2 too easy solution??

Might be. I was worried about this before https://github.com/pmndrs/jotai/discussions/2241#discussioncomment-7514559

himself65 avatar Nov 25 '23 18:11 himself65

Here is the minimum reproduction

https://stackblitz.com/edit/vitejs-vite-v2qh9v?file=src%2Fmain.ts

himself65 avatar Nov 25 '23 21:11 himself65

@Kamahl19 Hi, would you try to use https://github.com/huozhi/rollup-plugin-swc-preserve-directives to see if the error disappear

himself65 avatar Nov 25 '23 21:11 himself65

I get even more errors. Maybe I misunderstood. Should I just add it to the vite plugin?

Kamahl19 avatar Nov 26 '23 12:11 Kamahl19

I get even more errors. Maybe I misunderstood. Should I just add it to the vite plugin?

Could you please share you vite config?

himself65 avatar Nov 26 '23 21:11 himself65

I just tried, and there's only one warning that won't cause building interrupt.

main.js → output...
(!) Module level directives cause errors when bundled, "use client" in "node_modules/.pnpm/[email protected][email protected]/node_modules/jotai/esm/react.mjs" was ignored.
node_modules/.pnpm/[email protected][email protected]/node_modules/jotai/esm/react.mjs (1:0)
1: 'use client';
   ^
2: import ReactExports, { createContext, useContext, useRef, createElement, useReducer, useEffect, useDebugValue, useCal...
3: import { getDefaultStore, createStore } from 'jotai/vanilla';

himself65 avatar Nov 26 '23 21:11 himself65

Anyway, I'm working on a new implementation that won't cause this error

himself65 avatar Nov 26 '23 21:11 himself65

Can this be an upstream issue?

https://github.com/vitejs/vite/issues/15012

dai-shi avatar Nov 27 '23 23:11 dai-shi

Any updates on this? Anyone?

dai-shi avatar Feb 24 '24 14:02 dai-shi

Error is still here

https://stackblitz.com/edit/vitejs-vite-v2qh9v

~/projects/vitejs-vite-v2qh9v 2s
❯ npm run build

> [email protected] build
> tsc && vite build

vite v5.1.4 building for production...
node_modules/jotai/esm/react.mjs (1:0) Module level directives cause errors when bundled, "use client" in "node_modules/jotai/esm/react.mjs" was ignored.
✓ 12 modules transformed.
dist/index.html                0.38 kB │ gzip: 0.27 kB
dist/assets/index-Kr26tfIY.js  7.35 kB │ gzip: 3.07 kB
✓ built in 462ms

himself65 avatar Feb 26 '24 07:02 himself65

Related https://github.com/vitejs/vite/issues/15012#issuecomment-1825035992

himself65 avatar Feb 26 '24 07:02 himself65

thanks. btw, it's not "error" that stops building, but just "warning", correct?

dai-shi avatar Feb 26 '24 07:02 dai-shi

oh yeah, a warning

himself65 avatar Feb 26 '24 07:02 himself65