Current behavior
I have a fully-ESM project. I have a file boolean.ts like the following:
export const TRUE = true;
I try to import a value into one of my Cypress test files with an import like the following:
import { TRUE } from '../lib/boolean.js';
This fails with the following error:
Module not found: Error: Can't resolve '../lib/boolean.js' in '/Users/nathan/git/cypress-esm-fully-qualified-import-repro/cypress/e2e'
Looked for and couldn't find the file at the following paths:
[/Users/nathan/git/cypress-esm-fully-qualified-import-repro/cypress/lib/boolean.js]
[/Users/nathan/git/cypress-esm-fully-qualified-import-repro/cypress/lib/boolean.js.js]
[/Users/nathan/git/cypress-esm-fully-qualified-import-repro/cypress/lib/boolean.js.json]
[/Users/nathan/git/cypress-esm-fully-qualified-import-repro/cypress/lib/boolean.js.jsx]
[/Users/nathan/git/cypress-esm-fully-qualified-import-repro/cypress/lib/boolean.js.mjs]
[/Users/nathan/git/cypress-esm-fully-qualified-import-repro/cypress/lib/boolean.js.coffee]
[/Users/nathan/git/cypress-esm-fully-qualified-import-repro/cypress/lib/boolean.js.ts]
[/Users/nathan/git/cypress-esm-fully-qualified-import-repro/cypress/lib/boolean.js.tsx]
Desired behavior
Cypress should support TypeScript-style fully-qualified ESM imports where one can import a .ts file by using a .js extension. In the context of this particular example, import ... from './modules.js should import module.ts.
Test code to reproduce
https://github.com/nwalters512/cypress-esm-fully-qualified-import-repro. Ignore the fact that defining and importing a TRUE constant isn't a real-world scenario 😉
Cypress Version
12.12.0
Node version
18.12.0
Operating System
macOS 13.3.1
Debug Logs
Other
I believe webpack's resolve.extensionAlias will be useful here. The example from their docs is probably pretty close to what you want:
module.exports = {
//...
resolve: {
extensionAlias: {
'.js': ['.ts', '.js'],
'.mjs': ['.mts', '.mjs'],
},
},
};
Current behavior
I have a fully-ESM project. I have a file
boolean.tslike the following:I try to import a value into one of my Cypress test files with an import like the following:
This fails with the following error:
Desired behavior
Cypress should support TypeScript-style fully-qualified ESM imports where one can import a
.tsfile by using a.jsextension. In the context of this particular example,import ... from './modules.jsshould importmodule.ts.Test code to reproduce
https://github.com/nwalters512/cypress-esm-fully-qualified-import-repro. Ignore the fact that defining and importing a
TRUEconstant isn't a real-world scenario 😉Cypress Version
12.12.0
Node version
18.12.0
Operating System
macOS 13.3.1
Debug Logs
Other
I believe webpack's
resolve.extensionAliaswill be useful here. The example from their docs is probably pretty close to what you want: