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

Cannot import yjs using SvelteKit and adapter-static: SyntaxError: Cannot use import statement outside a module #2941

Closed
nokola opened this issue Nov 28, 2021 · 2 comments

Comments

@nokola
Copy link

nokola commented Nov 28, 2021

Describe the bug

Starting with a simple electron + web template for SvelteKit for experimentation. I tried adding yjs to it, but getting the error in Logs.
Works just fine in my non-sveltekit svelte app.

Reproduction

  1. Clone https://github.com/nokola/testSvelteKit
  2. Run:
yarn
yarn build

Expected: all OK
Actual: build error:

> Using @sveltejs/adapter-static
(node:16116) 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)
import * as Y from 'yjs' // eslint-disable-line
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29)
    at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
    at async Loader.import (internal/modules/esm/loader.js:166:24)
    at async Object.load_component (file:///D:/Repos/Local/my-app/.svelte-kit/output/server/chunks/app-024aa19a.js:1503:13)
    at async Promise.all (index 1)
(node:16116) UnhandledPromiseRejectionWarning: SyntaxError: Cannot use import statement outside a module
(node:16116) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled 
promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:16116) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
> 500 /
Error: 500 /
    at file:///D:/Repos/Local/my-app/node_modules/@sveltejs/kit/dist/chunks/index4.js:86:11
    at visit (file:///D:/Repos/Local/my-app/node_modules/@sveltejs/kit/dist/chunks/index4.js:222:5)
    at async prerender (file:///D:/Repos/Local/my-app/node_modules/@sveltejs/kit/dist/chunks/index4.js:303:6)
    at async Object.prerender (file:///D:/Repos/Local/my-app/node_modules/@sveltejs/kit/dist/chunks/index4.js:368:4)
    at async adapt (file:///D:/Repos/Local/my-app/node_modules/@sveltejs/adapter-static/index.js:13:4)
    at async adapt (file:///D:/Repos/Local/my-app/node_modules/@sveltejs/kit/dist/chunks/index4.js:393:2)
    at async file:///D:/Repos/Local/my-app/node_modules/@sveltejs/kit/dist/cli.js:896:5

Note: failure happens if yjs is used in any way, see index.svelte:

<script>
    import * as S from "y-websocket"
    S.test();
</script>

Logs

PS D:\Repos\GitHub\testSvelteKit> yarn build
yarn run v1.22.17
$ svelte-kit build
vite v2.6.14 building for production...
transforming (44) node_modules\lib0\conditions.js'test' is not exported by 'node_modules\y-websocket\src\y-websocket.js'
✓ 58 modules transformed.
.svelte-kit/output/client/_app/manifest.json                               2.04 KiB
.svelte-kit/output/client/_app/pages/__layout.svelte-25daf92b.js           1.54 KiB / gzip: 0.78 KiB
.svelte-kit/output/client/_app/error.svelte-6be86a66.js                    1.56 KiB / gzip: 0.75 KiB
.svelte-kit/output/client/_app/pages/index.svelte-e288b0c2.js              1.83 KiB / gzip: 0.94 KiB
.svelte-kit/output/client/_app/pages/page1.svelte-6e46b093.js              1.44 KiB / gzip: 0.72 KiB
.svelte-kit/output/client/_app/pages/page2.svelte-508cb7a1.js              1.48 KiB / gzip: 0.73 KiB
.svelte-kit/output/client/_app/pages/page3.svelte-06e9be0e.js              1.44 KiB / gzip: 0.72 KiB
.svelte-kit/output/client/_app/assets/start-61d1577b.css                   0.16 KiB / gzip: 0.15 KiB
.svelte-kit/output/client/_app/assets/pages/__layout.svelte-118da309.css   0.68 KiB / gzip: 0.40 KiB
.svelte-kit/output/client/_app/start-0f28ad9d.js                           18.94 KiB / gzip: 6.93 KiB
.svelte-kit/output/client/_app/assets/pages/index.svelte-1a7d65f4.css      0.32 KiB / gzip: 0.19 KiB
.svelte-kit/output/client/_app/chunks/vendor-d6b0b8d4.js                   7.32 KiB / gzip: 2.99 KiB
vite v2.6.14 building SSR bundle for production...
✓ 21 modules transformed.
.svelte-kit/output/server/app.js                        0.07 KiB
.svelte-kit/output/server/chunks/app-02114f6d.js        50.04 KiB
.svelte-kit/output/server/chunks/__layout-53c16722.js   0.60 KiB
.svelte-kit/output/server/chunks/error-b29df138.js      0.71 KiB
.svelte-kit/output/server/chunks/index-fb13d36b.js      1.30 KiB
.svelte-kit/output/server/chunks/page1-649e60b9.js      0.60 KiB
.svelte-kit/output/server/chunks/page2-575d970b.js      0.63 KiB
.svelte-kit/output/server/chunks/page3-422e4654.js      0.60 KiB

Run npm run preview to preview your production build locally.

> Using @sveltejs/adapter-static
(node:8212) 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)
D:\Repos\GitHub\testSvelteKit\node_modules\y-websocket\src\y-websocket.js:11
import * as Y from 'yjs' // eslint-disable-line
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29)
    at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
    at async Loader.import (internal/modules/esm/loader.js:166:24)
    at async Object.load_component (file:///D:/Repos/GitHub/testSvelteKit/.svelte-kit/output/server/chunks/app-02114f6d.js:1527:13)
    at async Promise.all (index 1)
(node:8212) UnhandledPromiseRejectionWarning: SyntaxError: Cannot use import statement outside a module
(node:8212) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:8212) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
> 500 /
Error: 500 /
    at file:///D:/Repos/GitHub/testSvelteKit/node_modules/@sveltejs/kit/dist/chunks/index4.js:86:11
    at visit (file:///D:/Repos/GitHub/testSvelteKit/node_modules/@sveltejs/kit/dist/chunks/index4.js:222:5)
    at async prerender (file:///D:/Repos/GitHub/testSvelteKit/node_modules/@sveltejs/kit/dist/chunks/index4.js:303:6)
    at async Object.prerender (file:///D:/Repos/GitHub/testSvelteKit/node_modules/@sveltejs/kit/dist/chunks/index4.js:368:4)
    at async adapt (file:///D:/Repos/GitHub/testSvelteKit/node_modules/@sveltejs/adapter-static/index.js:13:4)
    at async adapt (file:///D:/Repos/GitHub/testSvelteKit/node_modules/@sveltejs/kit/dist/chunks/index4.js:393:2)
    at async file:///D:/Repos/GitHub/testSvelteKit/node_modules/@sveltejs/kit/dist/cli.js:896:5
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
PS D:\Repos\GitHub\testSvelteKit>

System Info

System:
    OS: Windows 10 10.0.19043
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
    Memory: 32.57 GB / 47.92 GB
  Binaries:
    Node: 14.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.14.11 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (96.0.1054.29)     
    Internet Explorer: 11.0.19041.1202
  npmPackages:
    @sveltejs/adapter-node: next => 1.0.0-next.55 
    @sveltejs/adapter-static: next => 1.0.0-next.21 
    @sveltejs/kit: next => 1.0.0-next.201 
    svelte: ^3.29.0 => 3.44.2 
    vite: ^2.1.0 => 2.6.14

Severity

blocking all usage of SvelteKit

Additional Information

No response

@benmccann benmccann added vite and removed vite labels Nov 28, 2021
@benmccann
Copy link
Member

I see another user ran into issues with this library: #2639

This appears to be an issue in the library itself: yjs/y-websocket#72

@nokola
Copy link
Author

nokola commented Nov 28, 2021

Thanks for the investigation! Very useful!

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

No branches or pull requests

2 participants