Rich-Harris/svelte-cubed

Getting error require() of ES modules is not supported error

borsemayur2 opened this issue · 11 comments

Node: 14.18.1
OS: WSL (Win 11)
image

Getting same error on macOS 12

The code did run on codespaces, stackblitz but getting this error
image

try:

import { browser } from '$app/env';

if (browser) {
  // do browser stuff
}

Should sort out that second error you got there.

In the mean time, if anyone's got any clues for:

WARN  Local dependency not found at E:/KIT/kit/packages/kit
WARN  Local dependency not found at E:/sites/packages/site-kit

i.e. why the package.json file is:

{
  "devDependencies": {
    "@sveltejs/kit": "link:..\\KIT\\kit\\packages\\kit",
    },
    "pnpm": {
		"overrides": {
			"@sveltejs/kit": "link:../../KIT/kit/packages/kit",
			"@sveltejs/site-kit": "link:../../sites/packages/site-kit"
		}
	},
}

lemme know.

Edit: Yes, removing the overrides and specifying a recent version of svelte-kit worked for me, i.e.

{
  "devDependencies": {
		"@sveltejs/kit": "^1.0.0-next.198",
  }
}

then running pnpm install again, then pnpm dev worked

In the mean time, if anyone's got any clues for:

WARN  Local dependency not found at E:/KIT/kit/packages/kit
WARN  Local dependency not found at E:/sites/packages/site-kit

i.e. why the package.json file is:

{
  "devDependencies": {
    "@sveltejs/kit": "link:..\\KIT\\kit\\packages\\kit",
    },
    "pnpm": {
		"overrides": {
			"@sveltejs/kit": "link:../../KIT/kit/packages/kit",
			"@sveltejs/site-kit": "link:../../sites/packages/site-kit"
		}
	},
}

lemme know.

I ran into that too - guess those pnpm.overrides are dependencies on Rich's local directory tree.

Anyway, I opened issue #19 asking him to document them in README.md.

Cheers 👍

Node: 14.18.1 OS: WSL (Win 11) image

re: Error [ERR_REQUIRE_ESM] around OrbitControls

Getting the same error. Y'all found a fix for this?

No. I'm using stackblitz for the time being.

i dont have a solution yet but just went digging thru some github issues recently and found this: vitejs/vite#5197 so perhaps support is coming to vite although i was still not able to get it running on the default sveltekit.

at this point if you are trying out svelte-cubed i recommend trying it out separately from sveltekit as the compounded alpha software-ness is self inflicting some problems here.

start with this: https://github.com/sw-yx/svelte-cubed-starter or the REPL https://svelte.dev/repl/2200f07d5dc44843a0ecf15845cbe7b9?version=3.44.2

i don't know if it's the best solution, but i added the following to my svelte.config.js:

const config = {
	kit: {
		vite: {
			ssr: {
				noExternal: ["three"]
			}
		}
	}
};

I don't get the error anymore, tested with Sveltekit v1.0.0-next.201

@niklasgrewe Don't know either, but it gets rid of the error for me. Thank you very much!

Thanks everyone for your feedback!
I thought I was doing something very wrong for a moment.

@niklasgrewe I think it would be beneficial to include this solution/workaround in the svelte-cubed tutorial. Otherwise beginners like me are gonna be stumped on the very first step. I could open a PR integrating your solution into the tutorial. Let me know if You're cool with this!

@Return180bpm glad to hear it works for you too. That is a very good idea. You are welcome to take my solution and create a PR 👍