Jest: Error in jest dep. during serverless npm build

Created on 8 May 2020  ยท  6Comments  ยท  Source: facebook/jest

๐Ÿ› Bug Report

Hello, I'm trying to build a project which have jest as dependency. It's a Create React App based project.
I'm building the process through a serverless CI/CD for AWS Lambda environment (it launches a simple npm i / npm run build).
Two days ago I successfully deployed the project with no errors.
Today I'm getting an error during the build process at the following line in the jest-diff module:

import type { DiffOptions } from './types';

In the package.json file I've got the following dependencies configuration:

  • TypeScript version 3.5.2
  • Jest: 24.0.15

the same configuration of the last succesful build of two days ago.
I encounter the problem only in the AWS infrastructure, not locally.
Thanks in advance.

Bug Report Needs Repro Needs Triage

All 6 comments

Looks like you get jest-diff v25 or 26. If it's 25, upgrade to latest, it's fixed. If it's 26, upgrade TS to 3.8.

Sorry, I'm sure I'm using v24, and still getting the error during a CRA npm build in a remote environment (a Docker container hosted in AWS, created in a CI/CD configuration).
The React framework version is: 16.13.1.
The same configuration 2 days ago worked correctly.
So, since in my local env I got no build problems, I guess it can be a CDN problem in a specific node (already happened in the past with another dependency).

We've introduced import type syntax in v25, so at least one of your dependencies include jest-diff which is >=25. Try to track it down :) It's pretty straight forward if you have a lock file, which would also prevented differences between your local env and CI (at least with Yarn)

Ok, thank you, I already got the lock file. I solved upgrading TS at v3.8. I don't know why it is downloading jest >= 25. Anyway, project now has been build correctly, and it's working. Thank you again.

@thymikee [email protected] is imported from @types/[email protected] (see below).

That caused my project to break with the error mentioned in OP.

Upgrading to [email protected] comes with a host of issues in some projects, since not all libraries supports it well at the moment. In my case, jest wasn't importing non-ES5 or non-js modules correctly using [email protected] with default configurations after updating to [email protected].

As a workaround, downgrading [email protected] works pretty well.

@types/[email protected] probably shouldn't import [email protected] and import [email protected] instead.

EDIT: updating @types/[email protected] work and is clean. My types were out of date. My bad ๐Ÿ˜›


> npm ls jest-diff
...
โ”œโ”€โ”ฌ @types/[email protected]
โ”‚ โ””โ”€โ”ฌ @types/[email protected]
โ”‚   โ””โ”€โ”€ [email protected]
โ””โ”€โ”ฌ [email protected]
  โ””โ”€โ”ฌ [email protected]
    โ””โ”€โ”ฌ [email protected]
      โ””โ”€โ”ฌ @jest/[email protected]
        โ””โ”€โ”ฌ [email protected]
          โ”œโ”€โ”€ [email protected]
          โ””โ”€โ”ฌ [email protected]
            โ””โ”€โ”€ [email protected]

@jberube we don't control @types/jest, feel free to raise the issue there :)

Was this page helpful?
0 / 5 - 0 ratings