Closed mmailaender closed 1 year ago
This is not an issue with svelte-preprocess-react, but with@clerk/nextjs
and node
.
As @clerk/nextjs
is not bundled as an ESM package. (It's missing the "type": "module"
in it's package.json)
// test.js
import * as clerk from "@clerk/nextjs";
node test.js
(node:13751) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/bob/project/node_modules/.pnpm/@clerk+nextjs@4.23.3_next@13.4.19_react-dom@18.2.0_react@18.2.0/node_modules/@clerk/nextjs/dist/esm/index.js:1
import {
^^^^^^
SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1153:20)
at Module._compile (node:internal/modules/cjs/loader:1197:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:165:29)
at ModuleJob.run (node:internal/modules/esm/module_job:192:25)
at async DefaultModuleLoader.import (node:internal/modules/esm/loader:228:24)
at async loadESM (node:internal/process/esm_loader:40:7)
Node.js v20.5.1
Looks like Nextjs (and Webpack) does more processing than Vite, you might want to investigate it its possible pre-bundle the ssr dependencies.
The package does load in the browser, but needs an :
// vite.config.js
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [sveltekit()],
define: {
'process.env.__NEXT_STRICT_NEXT_HEAD': 'false'
},
});
If I try to import the following React/Nextjs component:
import { ClerkProvider } from "@clerk/nextjs";
insrc/routes/+layout.svelte
I'm getting the following errorStackblitz: https://stackblitz.com/edit/sveltejs-kit-template-default-wgzmck?file=src%2Froutes%2F%2Blayout.svelte