#Broken build when using canvas

23 messages · Page 1 of 1 (latest)

stoic geode
#

npm run dev - works
npm run build - fails

I don't need to use canvas on SSR - so if there is any way to make the build work without the canvas package that will be even better.

The error I'm getting:

Error [RollupError]: Unexpected character '' (Note that you need plugins to import files that are not JavaScript)

Demo repo to reproduce problem - https://github.com/gmadar/solid-start-failed-build

🙏

GitHub

Contribute to gmadar/solid-start-failed-build development by creating an account on GitHub.

GitHub

Extract native modules (.node files) while creating a rollup bundle and put them in one place - GitHub - danielgindi/rollup-plugin-natives: Extract native modules (.node files) while creating a rol...

GitHub

rollup version: v1.27.14 node version: v10.15.3 npm version: 6.13.4 syster: windows 10 When I pack it, i got this error: [!] Error: Unexpected character '�' (Note that you need plug...

proven fern
#

Did you try to use the built-in unstable_clientOnly instead of the custom? Yours solution is eagerly importing the component

stoic geode
#

no I haven't. new to Solid... how do I use it?

proven fern
#

Yup, I'll send you an example usage in a few minutes

#

It should properly treeshake the component out of the server bundle

stoic geode
proven fern
#

Give me 20 minutes and I'll try to fork it and play with it

proven fern
#

Basically - konva has some nasty side effects when importing which is causing the canvas package to be bundled into SSR result (which we don't even need in this case). I moved it to dynamic import inside onMount callback, but it can be also solved with some env variable/isServer check to prevent a waterfall. The clientOnly wasn't needed anymore so I deleted it also

stoic geode
#

ohh got it. nice! thank you!
Any idea why the clientOnly didn't work? since Konva was behind Stage I expected it to behave the same

proven fern
#

Tbh, I have no idea xD I'm surprised because of this as well. Maybe it's just because of the treeshaking stuff and Konva not being marked as a side-effect free 🤔

#

Maybe turning on more aggressive tree shaking would do the thing? I can check it later, because the dynamic import always complicates stuff

stoic geode
#

ok. Thanks that really helped

stoic geode
#

@proven fern - I think I found a bug.
unstable_clientOnly is now working for me - I've just removed canvas it from the package.json file
(updated the repo with the fix)

proven fern
#

That's strange, I checked it also 😂

#

Don't you get error in runtime after build?

stoic geode
#

yeah... there's a runtime error😵‍💫

proven fern
#

Okay, I found the problem with ClientOnly

#

It looks like vite isn't statically replacing the isServer variable that it's used inside, so it can't properly treeshake based on it.

#

Take a look at the new commit in my repo, the clientOnly is exact same version as in solid-start but I changed condition from isServer to import.meta.env.SSR

#

I'll try to tackle this issue upstream also