MrRefactoring / jira.js

A JavaScript/TypeScript wrapper for the JIRA Cloud, Service Desk and Agile REST API

Home Page:https://mrrefactoring.github.io/jira.js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Module not found: Error: Can't resolve 'crypto'

Coolranch opened this issue · comments

When adding the jira.js library to my CRA application and attempting to use the Version3Client I get the following error.

ERROR in ./node_modules/atlassian-jwt/dist/lib/jwt.js 61:15-32
Module not found: Error: Can't resolve 'crypto' in 'C:\projects\jira-helper\node_modules\atlassian-jwt\dist\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "crypto": false }

Here are my package versions:

"dependencies": {
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
"@types/jest": "^27.0.1",
"@types/node": "^16.7.13",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"antd": "^5.3.3",
"immer": "^9.0.21",
"jira.js": "^2.17.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.9.0",
"react-scripts": "5.0.1",
"typescript": "^4.4.2",
"use-immer": "^0.8.1",
"web-vitals": "^2.1.0"
}

commented

Install crypto-browserify as a devDependency

npm i --save-dev crypto-browserify

Add the path to the package in your tsconfig.json

"compilerOptions": {
   ...
  "paths": {
    "crypto": ["./node_modules/crypto-browserify"]