Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preset ts-jest is invalid: The "id" argument must be of type string. Received null #10035

Closed
lovefamilychildrenhappiness opened this issue May 13, 2020 · 11 comments

Comments

@lovefamilychildrenhappiness

🐛 Bug Report

To Reproduce

Steps to reproduce the behavior:

I use AWS CodeBuild to deploy a project and I invoke jest tests during the deployment. When the NODE_ENV is set to dev, there is no problem, but when NODE_ENV is set to production. I get the following error:

[Container] 2020/05/13 16:48:41 Running command npx jest -i src/spec/
--
142 | npx: installed 503 in 12.817s
143 | ● Validation Error:
144 |  
145 | Preset ts-jest is invalid:
146 |  
147 | The "id" argument must be of type string. Received null
148 | TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received null
149 | at validateString (internal/validators.js:117:11)
150 | at Module.require (internal/modules/cjs/loader.js:1037:3)
151 | at require (internal/modules/cjs/helpers.js:77:18)
152 | at setupPreset (/root/.npm/_npx/312/lib/node_modules/jest/node_modules/jest-config/build/normalize.js:289:14)
153 | at normalize (/root/.npm/_npx/312/lib/node_modules/jest/node_modules/jest-config/build/normalize.js:642:15)
154 | at readConfig (/root/.npm/_npx/312/lib/node_modules/jest/node_modules/jest-config/build/index.js:220:68)
155 | at async readConfigs (/root/.npm/_npx/312/lib/node_modules/jest/node_modules/jest-config/build/index.js:400:26)
156 | at async runCLI (/root/.npm/_npx/312/lib/node_modules/jest/node_modules/@jest/core/build/cli/index.js:198:59)
157 | at async Object.run (/root/.npm/_npx/312/lib/node_modules/jest/node_modules/jest-cli/build/cli/index.js:163:37)

I actually do have ts-jest installed and during the deployment I install the following as dev dependencies:

      - npm install i -D jest @types/jest ts-jest

I can confirm that ts-jest is installed during the deployment:

[Container] 2020/05/13 16:48:40 Running command npx ts-jest
--
128 | npx: installed 19 in 1.403s
129 |  
130 | Usage:
131 | ts-jest command [options] [...args]
132 |  
133 | Commands:
134 | config:init           Creates initial Jest configuration
135 | config:migrate        Migrates a given Jest configuration
136 | help [command]        Show this help, or help about a command
137 |  
138 | Example:
139 | ts-jest help config:migrate

If it was not installed, I would have gotten a ts-jest error above.

However, the next line contains this:

      - npx jest -i src/spec/

And this when the error happens. When NODE_ENV is set to production in the container, Jest seems to ignore the dev dependencies installed. This is wrong because I don't want to put jest and ts-jest into dependencies during my production deploy.

How am i able to address the problem?

@CubeSugarZhang
Copy link

I troubled this issue,too.

@peterjanes
Copy link

peterjanes commented May 27, 2020

I think this might be related to resolving the preset artifact with npx; perhaps it doesn't look in the local node_modules directory? With yarn v2 if I run yarn jest it fails similarly, but if I run yarn install (under v1) or npm install and then run yarn jest it works.

@SimenB
Copy link
Member

SimenB commented May 27, 2020

dev deps are not installed if NODE_ENV is production, see https://docs.npmjs.com/cli/install.

No idea if that's the issue here (I've never used, or heard of, AWS CodeBuild). If you think this is a bug with Jest, pleas open up a new issue with full reproduction steps, following the template

@SimenB SimenB closed this as completed May 27, 2020
@mcabrams
Copy link

mcabrams commented Jun 8, 2020

I'm getting this error as well, in local environment, with no usage of NODE_ENV being set to production. Seems specific to ts-jest, however.

@Robbie-Cook
Copy link

Robbie-Cook commented Jun 19, 2020

I just ran npm i --save-dev ts-jest again

@palashgupta98
Copy link

palashgupta98 commented Jul 4, 2020

@Robbie-Cook not working is there something I am missing?

@bxt
Copy link

bxt commented Sep 9, 2020

I see in your command that you run npx jest ... which means npm will download some version of jest and run it without using your dev dependencies. That's why jest can not find the preset. Instead you should change the command to say npm run jest ... then your bundled version of jest including all the dev dependencies should be run and it will hopefully work.

I think the jest error message is a bit confusing, since it does usually not mean that the preset is invalid, but rather that the preset is not there or at all or can not be found for some reason.

@mcabrams
Copy link

In my case, which I can't imagine will apply to anyone else, I happened to have a symlink to node_modules in the same folder as my jest.config.js - that seems to have prevented it from finding the preset. Not the best error message in that case.

@miguelangeltorresfp
Copy link

miguelangeltorresfp commented Sep 13, 2020

I'm testing the preset option in different local projects.
Only ts-jest preset works:

module.exports = {
...
  preset: 'ts-jest',
...
}

Neither of the other two works: js-with-ts - js-with-babel
For now I'm using the transform option in the jest config file:

const { jsWithTs: tsjPreset } = require('ts-jest/presets');

module.exports = {
...
  transform: {
    ...tsjPreset.transform,
    // [...]
  },
...
}

@francescov1
Copy link

If anyone is still running into this, I was able to resolve it without needing to install jest separately. I was running npm ci right before running npx jest, replacing the install command with NODE_ENV=development npm ci fixed the issue for me while ensuring the NODE_ENV stays set to production.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants