-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Describe the bug
When a CommonJS module that itself has CommonJS dependencies (and thus, uses require
) is installed from npm, it works without issue. However, when it is installed as a local dependency (from a path), it fails with a require is not defined
error.
To Reproduce
-
Create and initialise a new SvelteKit skeleton project (
npm init svelte@next reproduction
) -
Install @small-tech/remote
npm i @small-tech/remote
-
Update src/routes/index.svelte to add the following script block:
<script> import Remote from '@small-tech/remote' </script>
-
Run the project.
npm run dev
-
Hit http://localhost:3000 and note that it works as expected.
-
Clone a local copy of the Remote module into the same parent folder as the skeleton project from Step 1:
git clone https://github.com/small-tech/remote.git
-
Use the local copy of the Remote module in the skeleton project:
npm i ../remote
-
Run the project again, like we did in Step 4:
npm run dev
Expected behaviour
It should work exactly as before.
Actual behaviour
The following error is thrown:
10:09:46 AM [vite] Error when evaluating SSR module /@fs/home/aral/small-tech/small-web/remote/index.js:
ReferenceError: require is not defined
at /@fs/home/aral/small-tech/small-web/remote/index.js:12:14
at instantiateModule (/home/aral/sandbox/sveltekit-commonjs-local-dependencies/node_modules/vite/dist/node/chunks/dep-0ed4fbc0.js:69982:166)
require is not defined
ReferenceError: require is not defined
at /@fs/home/aral/small-tech/small-web/remote/index.js:10:14
at instantiateModule (/home/aral/sandbox/sveltekit-commonjs-local-dependencies/node_modules/vite/dist/node/chunks/dep-0ed4fbc0.js:69982:166)
Information about your SvelteKit Installation:
Diagnostics
-
System: OS: Linux 5.4 elementary OS 5.1.7 Hera CPU: (12) x64 Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz Memory: 687.24 MB / 15.51 GB Container: Yes Shell: 5.4.2 - /usr/bin/zsh Binaries: Node: 14.17.1 - ~/.nvm/versions/node/v14.17.1/bin/node Yarn: 1.22.5 - /usr/bin/yarn npm: 6.14.13 - ~/.nvm/versions/node/v14.17.1/bin/npm Browsers: Firefox: 89.0.1 npmPackages: @sveltejs/kit: next => 1.0.0-next.118 svelte: ^3.34.0 => 3.38.3
- Your browser: FireFox latest
- If using a community adapter, the adapter and version: n/a
Severity
It makes it difficult to test modules you’re developing alongside your app as you have to publish them before you can test them in your SvelteKit project.