playwright: [BUG] Extension required when importing other files with type="module"
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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 24 (4 by maintainers)
Name the file with .ts, but try importing it with a .js extension.
It works! THANKS!