Repository navigation
Closed as not planned
Labels
Description
Describe the bug
For a given package, there are sometimes differences in how it behaves in build/production than from dev. This is one such example, where a module that I import (default export) can be called fine in dev, but it errors in build step.
Reproduction
https://github.com/tarngerine/not-a-function
- npm install, npm run dev
- check console, it should log something like below
-
now run
npm run build -
expected: no error
-
actual: error (see log)
Logs
TypeError: CodeBlock.extend is not a function
at file:///Users/tarng/Code/not-a-function/.svelte-kit/output/server/entries/pages/index.svelte.js:3:11
at ModuleJob.run (node:internal/modules/esm/module_job:197:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
at async Promise.all (index 1)
at async respond$1 (file:///Users/tarng/Code/not-a-function/.svelte-kit/output/server/index.js:1862:13)
at async resolve (file:///Users/tarng/Code/not-a-function/.svelte-kit/output/server/index.js:2225:114)
at async respond (file:///Users/tarng/Code/not-a-function/.svelte-kit/output/server/index.js:2180:22)
at async visit (file:///Users/tarng/Code/not-a-function/node_modules/@sveltejs/kit/dist/vite.js:1229:20)
[vite-plugin-svelte-kit] 500 /
error during build:
Error: 500 /
at file:///Users/tarng/Code/not-a-function/node_modules/@sveltejs/kit/dist/vite.js:1128:11
at save (file:///Users/tarng/Code/not-a-function/node_modules/@sveltejs/kit/dist/vite.js:1347:4)
at visit (file:///Users/tarng/Code/not-a-function/node_modules/@sveltejs/kit/dist/vite.js:1238:3)System Info
System:
OS: macOS 12.4
CPU: (10) arm64 Apple M1 Pro
Memory: 219.05 MB / 32.00 GB
Shell: 3.2.2 - /usr/local/bin/fish
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.18 - /usr/local/bin/yarn
npm: 8.5.0 - /usr/local/bin/npm
Browsers:
Brave Browser: 102.1.39.111
Firefox: 94.0.2
Safari: 15.5
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.62
@sveltejs/kit: next => 1.0.0-next.379
svelte: ^3.44.0 => 3.49.0
vite: ^3.0.0 => 3.0.2Severity
blocking an upgrade
Additional Information
i implemented this example after the switch to vite 3, so not sure if it would break before that. it's really hard to make a "old svelte project" given how many configs have changed, so i can't easily compare

Activity
Wobbley commentedon Jul 19, 2022
I am not 100% sure this is the same issue I had back in March, but I had an issue with a library where it would run in dev mode, but not in build. I got the following answer on Discord:
bluwy commentedon Jul 19, 2022
This is an inconsistency issue in Vite, but it's also because the
@tiptap/extension-code-blockpackage isn't nodejs friendly, hence it's failing in build, but works in dev (because dev runs as part of Vite's bundler, not nodejs). If you inspect both CJS code, which is the one loaded in build and nodejs, you can see that it doesn't export asexports = CodeBlock, but insteadexports["default"] = CodeBlock. A fix (like the above comment suggested) is to use named imports, likeimport { CodeBlock } from '@tiptap/extension-code-block';as that is exported correctly and works in nodejs.Since the package had already export ESM code, which should be used in build, and can also avoid this issue in the first place. You can request for them to use the package
exportsfield to resolve this. See https://publint.bjornlu.com/@tiptap/extension-code-block@2.0.0-beta.42Closing as this is out of scope of SvelteKit.