Ts-jest: TS imports with .js extension break Jest-resolve

Created on 4 Apr 2019  路  2Comments  路  Source: kulshekhar/ts-jest

Issue :

TypeScript files using web-compatible ES6 imports cause Jest to throw an error about not being able to find the module. This error comes from jest-resolve/build/index.js:229 and happens regardless of the module type specified in ts-jest (commonjs, amd, ES6, etc.)

Expected behavior :

TypeScript supports adding a .js extension to import statements for web-compatibility (since imports require a full path, including the extension).

I would expect ts-jest to allow TypeScript to handle this and convert it to commonjs before it gets passed to jest.

Minimal repo :

/* user.ts */
export class User {
  public name : string;

  constructor(name : string) {
    this.name = name;
  }
}
/* user.spec.ts */
import { User } from './user.js';

describe('User', function() {
});

Most helpful comment

I set up a custom resolver and just published it to npm: jest-ts-webcompat-resolver

All 2 comments

I facing the same issue :(
The problem it is the jest-resolve is managed by jest :(

Maybe we must to create a custom resolver for jest as workaround to solve this issue.

I set up a custom resolver and just published it to npm: jest-ts-webcompat-resolver

Was this page helpful?
0 / 5 - 0 ratings

Related issues

qm3ster picture qm3ster  路  3Comments

bySabi picture bySabi  路  4Comments

stangerjm picture stangerjm  路  4Comments

stephenotalora picture stephenotalora  路  3Comments

artola picture artola  路  3Comments