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

TypeScript installation works with tests/test.ts, not tests/test.js #4341

Closed
jtlapp opened this issue Mar 15, 2022 · 0 comments · Fixed by #4368
Closed

TypeScript installation works with tests/test.ts, not tests/test.js #4341

jtlapp opened this issue Mar 15, 2022 · 0 comments · Fixed by #4368
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.
Milestone

Comments

@jtlapp
Copy link

jtlapp commented Mar 15, 2022

Describe the bug

I answered 'yes' to installing with TypeScript, but yarn test and npm test would bomb with this error:

Error [ERR_REQUIRE_ESM] [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/joe/repos/cavesite/tests/test.js

I solved the problem by renaming tests/test.js to tests/test.ts.

The main problem with this is that it sent me for a spin around the Internet trying to figure out how to get things working.

(Aside: I'm still trying to figure out how to run src/**/*.test.ts unit tests, via either playwright or jest.)

Reproduction

  1. Install SvelteKit with TypeScript.
  2. Run yarn test or npm test.

Logs

Error [ERR_REQUIRE_ESM] [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/joe/repos/cavesite/tests/test.js
require() of ES modules is not supported.
require() of /Users/joe/repos/cavesite/tests/test.js from /Users/joe/repos/cavesite/node_modules/@playwright/test/lib/loader.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename test.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/joe/repos/cavesite/package.json.


    at new NodeError (internal/errors.js:322:7)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1102:13)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Loader._requireOrImport (/Users/joe/repos/cavesite/node_modules/@playwright/test/lib/loader.js:244:14)
    at Loader.loadTestFile (/Users/joe/repos/cavesite/node_modules/@playwright/test/lib/loader.js:142:18)
    at Runner._runFiles (/Users/joe/repos/cavesite/node_modules/@playwright/test/lib/runner.js:295:44)
    at Runner._run (/Users/joe/repos/cavesite/node_modules/@playwright/test/lib/runner.js:231:12)
    at TimeoutRunner.run (/Users/joe/repos/cavesite/node_modules/playwright-core/lib/utils/async.js:38:14)
    at raceAgainstTimeout (/Users/joe/repos/cavesite/node_modules/playwright-core/lib/utils/async.js:85:15)
    at Runner.runAllTests (/Users/joe/repos/cavesite/node_modules/@playwright/test/lib/runner.js:188:20)
    at runTests (/Users/joe/repos/cavesite/node_modules/@playwright/test/lib/cli.js:184:18)
    at Command.<anonymous> (/Users/joe/repos/cavesite/node_modules/@playwright/test/lib/cli.js:79:7)

System Info

System:
    OS: macOS 10.15.5
    CPU: (4) x64 Intel(R) Core(TM) i3-8100B CPU @ 3.60GHz
    Memory: 747.37 MB / 32.00 GB
    Shell: 5.0.11 - /usr/local/bin/bash
  Binaries:
    Node: 14.18.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 8.1.4 - /usr/local/bin/npm
  Browsers:
    Chrome: 99.0.4844.51
    Safari: 13.1.1
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.31 
    @sveltejs/kit: ^1.0.0-next.298 => 1.0.0-next.298 
    svelte: ^3.44.0 => 3.46.4

Severity

annoyance

Additional Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1-important SvelteKit cannot be used by a large number of people, basic functionality is missing, etc.
Projects
None yet
2 participants