sveltejs / kit

web development, streamlined
https://svelte.dev/docs/kit
MIT License
18.71k stars 1.94k forks source link

RollupError: Unexpected character '�' #11416

Closed devcsrj closed 10 months ago

devcsrj commented 10 months ago

Describe the bug

After upgrading to sveltekit 2, I am getting this error:

> Using @sveltejs/adapter-node
error during build:
RollupError: Unexpected character '�'
    at error (file:///...node_modules/rollup/dist/es/shared/parseAst.js:337:30)
    at nodeConverters (file:///...node_modules/rollup/dist/es/shared/parseAst.js:2084:9)
    at convertNode (file:///...node_modules/rollup/dist/es/shared/parseAst.js:969:12)
    at convertProgram (file:///...node_modules/rollup/dist/es/shared/parseAst.js:960:48)
    at parseAstAsync (file:///...node_modules/rollup/dist/es/shared/parseAst.js:2150:20)
    at async Module.tryParseAsync (file:///...node_modules/rollup/dist/es/shared/node-entry.js:13513:21)
    at async Module.setSource (file:///...node_modules/rollup/dist/es/shared/node-entry.js:13094:35)
    at async ModuleLoader.addModuleSource (file:///...node_modules/rollup/dist/es/shared/node-entry.js:17757:13)

I have no idea what unicode character is that supposed to be.

Reproduction

No idea how to reproduce yet. If someone can guide me on how to print verbose logs, that would be helpful! That way I can pinpoint which source exactly is it failing to parse

Logs

No response

System Info

System:
    OS: macOS 14.2
    CPU: (8) arm64 Apple M1 Pro
    Memory: 66.70 MB / 16.00 GB
    Shell: 3.6.0 - /opt/homebrew/bin/fish
  Binaries:
    Node: 20.3.0 - ~/.local/share/nvm/v20.3.0/bin/node
    Yarn: 1.22.19 - ~/.local/share/nvm/v20.3.0/bin/yarn
    npm: 9.6.7 - ~/.local/share/nvm/v20.3.0/bin/npm
    pnpm: 8.10.2 - ~/.local/share/nvm/v20.3.0/bin/pnpm
    bun: 1.0.0 - ~/.bun/bin/bun
    Watchman: 2023.11.27.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 120.0.6099.109
    Safari: 17.2
  npmPackages:
    @sveltejs/adapter-node: ^2.0.1 => 2.0.1 
    @sveltejs/kit: ^2.0.4 => 2.0.4 
    @sveltejs/vite-plugin-svelte: ^3.0.1 => 3.0.1 
    svelte: ^4.2.8 => 4.2.8 
    vite: ^5.0.10 => 5.0.10

Severity

blocking an upgrade

Additional Information

No response

devcsrj commented 10 months ago

After purging directories (node_modules, package-lock.json, build) and so on, I can't seem to reproduce this anymore. In the meantime I'll close this issue.

P.S.: If someone can guide me on how to print verbose logs, this will still be helpful 🙏

bartvdbraak commented 9 months ago

[23:58:44] Running build in Washington, D.C., USA (East) – iad1
[23:58:44] Cloning github.com/bartvdbraak/hellob.art (Branch: feat/dynamic-og-images, Commit: 1be9ad4)
[23:58:45] Cloning completed: 588.445ms
[23:58:49] Restored build cache
[23:58:49] Running "vercel build"
[23:58:50] Vercel CLI 33.1.0
[23:58:50] Detected `pnpm-lock.yaml` version 6 generated by pnpm 8
[23:58:50] Installing dependencies...
[23:58:51] Lockfile is up to date, resolution step is skipped
[23:58:51] Progress: resolved 1, reused 0, downloaded 0, added 0
[23:58:51] Packages: +30 -1
[23:58:51] ++++++++++++++++++++++++++++++-
[23:58:52] Progress: resolved 30, reused 0, downloaded 30, added 30, done
[23:58:52] .../node_modules/@sveltejs/kit postinstall$ node postinstall.js
[23:58:53] .../node_modules/@sveltejs/kit postinstall: Done
[23:58:54] 
[23:58:54] dependencies:
[23:58:54] + @ethercorps/sveltekit-og 3.0.0
[23:58:54] + @types/node 20.11.5
[23:58:54] 
[23:58:54] 
[23:58:54] > hellob.art@1.0.0 prepare /vercel/path0
[23:58:54] > npx husky install && svelte-kit sync && svelte-check --tsconfig ./tsconfig.json
[23:58:54] 
[23:58:55] npm WARN exec The following package was not found and will be installed: husky@8.0.3
[23:58:56] husky - Git hooks installed
[23:58:57] 
[23:58:57] ====================================
[23:58:57] Loading svelte-check in workspace: /vercel/path0
[23:58:57] Getting Svelte diagnostics...
[23:58:57] 
[23:59:06] ====================================
[23:59:06] svelte-check found 0 errors and 0 warnings
[23:59:06] Done in 15.8s
[23:59:06] Running "pnpm run build"
[23:59:07] 
[23:59:07] > hellob.art@1.0.0 build /vercel/path0
[23:59:07] > vite build
[23:59:07] 
[23:59:08] 10:59:08 PM [vite-plugin-svelte] WARNING: The following packages have a svelte field in their package.json but no exports condition for svelte.
[23:59:08] 
[23:59:08] radix-icons-svelte@1.2.1
[23:59:08] svelte-wrap-balancer@0.0.4
[23:59:08] 
[23:59:08] Please see https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#missing-exports-condition for details.
[23:59:08] vite v5.0.11 building SSR bundle for production...
[23:59:08] transforming...
[23:59:17] ✓ 519 modules transformed.
[23:59:17] [commonjs--resolver] Unexpected character '\u{7f}' (Note that you need plugins to import files that are not JavaScript)
[23:59:17] file: /vercel/path0/node_modules/.pnpm/@resvg+resvg-js@2.6.0/node_modules/@resvg/resvg-js/index.js:1:0
[23:59:17] 1: ELF>�Q@(�@@8 @�O�O...
[23:59:17]    ^
[23:59:17] 2: ��
[23:59:17] 3: PO>P_>P_>��`0�@0�@0�@00...
[23:59:17] error during build:
[23:59:17] RollupError: Unexpected character '\u{7f}'
[23:59:17]     at error (file:///vercel/path0/node_modules/.pnpm/rollup@4.9.5/node_modules/rollup/dist/es/shared/parseAst.js:337:30)
[23:59:17]     at nodeConverters (file:///vercel/path0/node_modules/.pnpm/rollup@4.9.5/node_modules/rollup/dist/es/shared/parseAst.js:2084:9)
[23:59:17]     at convertNode (file:///vercel/path0/node_modules/.pnpm/rollup@4.9.5/node_modules/rollup/dist/es/shared/parseAst.js:969:12)
[23:59:17]     at convertProgram (file:///vercel/path0/node_modules/.pnpm/rollup@4.9.5/node_modules/rollup/dist/es/shared/parseAst.js:960:48)
[23:59:17]     at parseAstAsync (file:///vercel/path0/node_modules/.pnpm/rollup@4.9.5/node_modules/rollup/dist/es/shared/parseAst.js:2150:20)
[23:59:17]     at async Module.tryParseAsync (file:///vercel/path0/node_modules/.pnpm/rollup@4.9.5/node_modules/rollup/dist/es/shared/node-entry.js:13517:20)
[23:59:17]     at async Module.setSource (file:///vercel/path0/node_modules/.pnpm/rollup@4.9.5/node_modules/rollup/dist/es/shared/node-entry.js:13098:35)
[23:59:17]     at async ModuleLoader.addModuleSource (file:///vercel/path0/node_modules/.pnpm/rollup@4.9.5/node_modules/rollup/dist/es/shared/node-entry.js:17788:13)
[23:59:24]  ELIFECYCLE  Command failed with exit code 1.
[23:59:24] Error: Command "pnpm run build" exited with 1
[23:59:25] 

Currently encountering this exact problem on a branch of mine, see the following PR: https://github.com/bartvdbraak/hellob.art/pull/207

Anyone knows what I can do to overcome this error?

rbozan commented 9 months ago

@bartvdbraak How did you solve this? 🤔 Guess it has to do something with the OG image generation, as I also have that, but what's the fix?

multiplehats commented 9 months ago

Not sure what the fix is, i ditched the OG image gen hahahah

aaronjbecker commented 8 months ago

@multiplehats @rbozan @bartvdbraak This issue has something to do with vite trying to bundle the rust binary that resvg uses (resvg-js is server-side only for this reason). I overcame this issue using the approach outlined in this resvg-js issue. Install @resvg/resvg-js as a non-dev dependency, then add this section in your vite.config.js/ts:

    build: {
        rollupOptions: {
            external: ['@resvg/resvg-js']
        }
    }

With sveltekit-og, you'll also encounter another issue related to using svelte/compiler and one of its dependencies. This comment on a related issue provides some snippets that hopefully help when using sveltekit-og under adapter-node.

jorisw commented 8 months ago

I'm having the same issue but am not using resvg. Any ideas how how to get Rollup to mention the file where the character was encountered?

Edit: Rollup 4.13.0 is said to know mention the file that the character was found in, though I haven't been able to get that to work. The following addition to one of the files in node_module has helped me find out which file it was however:

node_modules/rollup/dist/es/shared/parseAst.js:374:

function getRollupError(base) {
+ console.log(base.id)

... this will print the path to the offending file above the build error.

lilouartz commented 6 months ago

This was exactly the issue I was trying to fix! Thanks

vhochstein commented 5 months ago

I ve got a similar issue... Ive tried cleaning everything. I ve tried several node version 18 and 20. I ve tried different OS, MacOS Ubuntu.

Any idea what I might try to fix this ?

I always get: /Users/volkerhochstein/projects/node/magic-pull/node_modules/@node-rs/argon2-darwin-arm64/argon2.darwin-arm64.node error during build: RollupError: Unexpected character '�' at getRollupError (file:///Users/volkerhochstein/projects/node/magic-pull/node_modules/rollup/dist/es/shared/parseAst.js:395:41) at ParseError.initialise (file:///Users/volkerhochstein/projects/node/magic-pull/node_modules/rollup/dist/es/shared/node-entry.js:11332:28) at convertNode (file:///Users/volkerhochstein/projects/node/magic-pull/node_modules/rollup/dist/es/shared/node-entry.js:13082:10)

roebuk commented 3 months ago

In my case, I was using @node-rs/argon2. The logging mentioned in https://github.com/sveltejs/kit/issues/11416#issuecomment-1980805816 helped track this down

I had to move @node-rs/argon2 from my devDependencies to my dependencies within package.json. Then add the following to my vite.config.ts:

build: {
  rollupOptions: {
    external: ['@node-rs/argon2']
  }
}
tylercollier commented 2 months ago

Similar to https://github.com/sveltejs/kit/issues/11416#issuecomment-2227390811 (thanks roebuck for the tip!):

I am using lucia-auth, which depends on oslo, which depends on argon2. So @node-rs/argon2 was not in my package.json dependencies directly. I added it there, and then building worked. I did not need the change to vite.config.ts (the build->rollupOptions->external section).

jycouet commented 2 months ago

Similar to #11416 (comment) (thanks roebuck for the tip!):

I am using lucia-auth, which depends on oslo, which depends on argon2. So @node-rs/argon2 was not in my package.json dependencies directly. I added it there, and then building worked. I did not need the change to vite.config.ts (the build->rollupOptions->external section).

I think that you can even remove @node-rs/argon2 and put oslo in your dependencies (NOT devDependencies) Could you check I'm curious :)

tylercollier commented 2 months ago

@jycouet I tried taking out @node-rs/argon2 of dependencies and instead using oslo and I got the message `RollupError: Unexpected character '\u{7f}' once more.

jycouet commented 2 months ago

Thank you for trying out and letting me know. This is a mistery for me! 🔮

ondrejrohon commented 2 months ago

I had Oslo as my dependency, and this to vite.config didn't help.

build: {
    rollupOptions: {
      external: ['@node-rs/argon2']
    }
  }

What worked was explicitly adding @node-rs/argon2 to dependencies

tymonTe commented 2 months ago

in my case the issue was caused by fsevents

adding rollupOptions to vite.config.ts fixed the issue for me:

import {sveltekit} from '@sveltejs/kit/vite'
import {defineConfig} from 'vitest/config'

export default defineConfig({
    plugins: [sveltekit()],
    test: {
        include: ['test/**/*.{test,spec}.{js,ts}']
    },
    ssr: {
        external: ['reflect-metadata']
    },
    build: {
        rollupOptions: {
            external: ['fsevents']
        }
    }
})
Bewinxed commented 1 month ago

external: ['@node-rs/argon2']

God bless your soul