[BUG] Extension required when importing other files with type="module"
See original GitHub issueContext:
## 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:
- Created a year ago
- Reactions:2
- Comments:23 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It works! THANKS!
Name the file with .ts, but try importing it with a .js extension.