(imported default) is not a function
See original GitHub issueDescribe the bug when I import an ES module (that also expose a cjs version) with default export, svelte-kit fails when building (static adapter) It works fine on dev
Logs
TypeError: WalletStores is not a function
at file:///home/wighawag/dev/wighawag/templates/jolly-roger/web/.svelte-kit/output/server/app.js:1055:22
at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
at async Loader.import (internal/modules/esm/loader.js:166:24)
at async prerender (file:///home/wighawag/dev/wighawag/templates/jolly-roger/node_modules/.pnpm/@sveltejs+kit@1.0.0-next.109_svelte@3.38.2/node_modules/@sveltejs/kit/dist/chunks/index5.js:79:14)
at async Object.prerender (file:///home/wighawag/dev/wighawag/templates/jolly-roger/node_modules/.pnpm/@sveltejs+kit@1.0.0-next.109_svelte@3.38.2/node_modules/@sveltejs/kit/dist/chunks/index5.js:296:5)
at async adapt (file:///home/wighawag/dev/wighawag/templates/jolly-roger/node_modules/.pnpm/sveltejs-adapter-ipfs@0.1.4/node_modules/sveltejs-adapter-ipfs/index.js:21:4)
at async adapt (file:///home/wighawag/dev/wighawag/templates/jolly-roger/node_modules/.pnpm/@sveltejs+kit@1.0.0-next.109_svelte@3.38.2/node_modules/@sveltejs/kit/dist/chunks/index5.js:322:2)
at async file:///home/wighawag/dev/wighawag/templates/jolly-roger/node_modules/.pnpm/@sveltejs+kit@1.0.0-next.109_svelte@3.38.2/node_modules/@sveltejs/kit/dist/cli.js:616:5
To Reproduce
git clone https://github.com/wighawag/jolly-roger.git
cd jolly-roger
git checkout sveltekit-bug-default-import
pnpm i
pnpm web:build staging
Information about your SvelteKit Installation:
Diagnostics
- The output of
npx envinfo --system --npmPackages svelte,@sveltejs/kit,vite --binaries --browsers
System:
OS: Linux 5.11 Ubuntu 21.04 (Hirsute Hippo)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
Memory: 3.81 GB / 15.43 GB
Container: Yes
Shell: 5.8 - /usr/bin/zsh
Binaries:
Node: 14.16.1 - ~/.volta/tools/image/node/14.16.1/bin/node
Yarn: 1.22.10 - ~/.volta/tools/image/yarn/1.22.10/bin/yarn
npm: 6.14.12 - ~/.volta/tools/image/node/14.16.1/bin/npm
Browsers:
Chrome: 90.0.4430.93
Firefox: 88.0.1
npmPackages:
svelte: ^3.38.2 => 3.38.2
- Your browser
Chrome: 90.0.4430.93
- Your adapter (e.g. Node, static, Vercel, Begin, etc…)
Severity While I can get around it via this line : https://github.com/wighawag/jolly-roger/blob/82b113f47043e11b9532a3527462ec17c67c6fca/web/src/lib/stores/wallet.ts#L13 I consider the issue critical as svelte-kit/vite is supposed to work with ES module natively.
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (6 by maintainers)
Top Results From Across the Web
Typescript/babel import causing "_1.default is not a function"
I have managed to fix it by adding "esModuleInterop": true to tsconfig.json . https://www.typescriptlang.org/docs/handbook/compiler-options.
Read more >react__webpack_imported_mod...
import { createContext } from 'react';. Open side panel. TypeError: react__WEBPACK_IMPORTED_MODULE_0___default is not a function or its return value is not ...
Read more >Export default was not found Error in JavaScript | bobbyhadz
The "export default was not found" error occurs when we try to import as default from a module that doesn't have a default...
Read more >(0 , import_defineToJSON.default) is not a function - Bugs
When trying to import '@8base/auth' to a Vite+Vue 3 project, the following error is trigger by the import statement. Uncaught TypeError: (0 ...
Read more >Fix __webpack_imported_module_ is not a function ... - hinty
This way is called named import, not so bad actually, there are a lot of advantages comparing to my previous export default method....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ha, I thought about that but did not try. I actually worked around the issue by export a named field instead of using the default export.
Yes, if adapter-static/node uses the esm export, then it should work as usual.
I think I know why you’re getting
Cannot use import statement outside a module
. You’re exporting the ESM files in.js
. For commonjs projects (web3w
), you need to export them as.mjs
.