question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Extension required when importing other files with type="module"

See original GitHub issue

Context:

## System:
 - OS: macOS 12.2.1
 - Memory: 802.27 MB / 32.00 GB
## Binaries:
 - Node: 16.13.1 - ~/.volta/tools/image/node/16.13.1/bin/node
 - Yarn: 1.22.17 - ~/.volta/bin/yarn
 - npm: 8.3.0 - ~/.volta/tools/image/npm/8.3.0/bin/npm
## Languages:
 - Bash: 3.2.57 - /bin/bash

Describe the bug

I am using type=“module” in my package.json, and running with PW_EXPERIMENTAL_TS_ESM=1. I found that when I attempt to import another of my files from my global setup file, I need to specify the full filename with extension, which I think is a node esm requirement, but then typescript complains with An import path cannot end with a '.ts' extension. Consider importing './generateTOTP' instead.. If I don’t include the extension, playwright will not start and I get an error of:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/xxx/e2e/config/generateTOTP' imported from /xxx/e2e/config/global-setup.ts

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:23 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
frederikhorscommented, Mar 30, 2022

It works! THANKS!

1reaction
IanVScommented, Mar 30, 2022

Name the file with .ts, but try importing it with a .js extension.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why am I getting this error upon trying to import a module from ...
If I just try to run the Main.js file, it tells me to either use the type: "module" on the package.json file or...
Read more >
Use file extension in imports if type: "module" is ... - YouTrack
When WS inspection discovers a missing import, and the user selects "import" (instead of "require"), the inserted code should include the file extension....
Read more >
Modules, introduction - The Modern JavaScript Tutorial
A module is a file. To make import/export work, browsers need <script type="module"> . · Modules have their own, local top-level scope and ......
Read more >
rollup.js
If you want to write your configuration as a CommonJS module using require and module.exports , you should change the file extension to...
Read more >
How we employed the new ECMAScript Module Support in ...
Why use ECMAScript modules (import) instead of CommonJS (require)? ... an error for files without a extension so you will have to import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found