Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
borsemayur2 opened this issue Nov 23, 2021 · 11 comments · May be fixed by #31
Open

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

borsemayur2 opened this issue Nov 23, 2021 · 11 comments · May be fixed by #31

Comments

@borsemayur2
Copy link

borsemayur2 commented Nov 23, 2021

Node: 14.18.1
OS: WSL (Win 11)
image

@borsemayur2
Copy link
Author

Getting same error on macOS 12

@borsemayur2
Copy link
Author

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

@DefinitelyMaybe
Copy link

DefinitelyMaybe commented Nov 23, 2021

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

@delhanty
Copy link

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.

@DefinitelyMaybe
Copy link

Cheers 👍

@tsxoxo
Copy link

tsxoxo commented Nov 25, 2021

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?

@borsemayur2
Copy link
Author

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

@swyxio
Copy link

swyxio commented Nov 28, 2021

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

@niklasgrewe
Copy link

niklasgrewe commented Nov 30, 2021

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

@tsxoxo
Copy link

tsxoxo commented Nov 30, 2021

@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!

@niklasgrewe
Copy link

@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 👍

tsxoxo added a commit to tsxoxo/svelte-cubed that referenced this issue Dec 1, 2021
Following the getting started tutorial as is causes a crash on the very first programming step for me and others - for details see issue Rich-Harris#16. This workaround seems to fix that. 
 
Solution suggested by @niklasgrewe in Rich-Harris#16 (comment)

Fixes Rich-Harris#16
@tsxoxo tsxoxo linked a pull request Dec 1, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants