SyntaxError: Named export 'xxx' not found. The requested module 'xxx.js' is a CommonJS module, #1149
Answered
by
brillout
EralChen
asked this question in
Help & Questions
-
Hi! Thanks for Reading I just // index.page.vue
<script lang="ts" setup>
import MapView from '@arcgis/core/views/MapView'
</script> And got Error 15:51:15 [vike][request(1)] HTTP request: /
15:51:18 [vite][request(1)] Error when evaluating SSR module /pages/index.page.vue: failed to import "@arcgis/core/views/MapView"
|- file:///D:/projectCode/%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%BA%94%E7%94%A8/zz-platform-template/node_modules/.pnpm/@[email protected]/node_modules/@esri/calcite-components/dist/components/index.js:6
export { getAssetPath, setAssetPath, setNonce, setPlatformOptions } from '@stencil/core/internal/client/index.js';
^^^^^^^^^^^^
SyntaxError: Named export 'getAssetPath' not found. The requested module '@stencil/core/internal/client/index.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from '@stencil/core/internal/client/index.js';
const { getAssetPath, setAssetPath, setNonce, setPlatformOptions } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at ModuleJob.run (node:internal/modules/esm/module_job:190:5)
That's ok in SPA. Is there any way to import and use it? A simple demo you can try at https://github.com/EralChen/simple-ssr |
Beta Was this translation helpful? Give feedback.
Answered by
brillout
Sep 28, 2023
Replies: 1 comment 10 replies
-
It's a common issue with ESM-CJS. It's unrelated to Vike. If you can provide a minimal reproduction then I'll have a look at it. |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd use https://github.com/cyco130/vite-plugin-cjs-interop to fix the issue. Alternatively, you can add the problematic npm package to
ssr.noExternal
.Also,
vike-vue
has anssr: boolean
flag which allows you to seamlessly disable SSR. This means you can disable SSR for your map pages while using SSR for your other pages. You can use Bati to scaffold avike-vue
app.If you want SSR for the outer part of your map pages, you can wrap your map in a
<ClientOnly>
component so that it's imported only on the client-side.Let me know how it goes.