Reputation: 183
My project is suddenly having a build error. My current repo still has no problem, it only happens when I clone the repo to a new folder and install the package again then do npm run build. So I am so scared to update the package right now...
I checked the merge history, I don't think any code merge should cause this issue..
Here is the error message I got:
$ npm run build
> [email protected] build I:\ds\projects\new\container-service\client
> craco build
Creating an optimized production build...
Failed to compile.
I:/ds/projects/new/container-service/client/src/views/add-application/AddApplicationPage.tsx
TypeScript error in I:/ds/projects/new/container-service/client/src/views/add-application/AddApplicationPage.tsx(4,25):
Could not find a declaration file for module 'history'. 'I:/ds/projects/new/container-service/client/node_modules/history/index.js' implicitly has an 'any' type.
If the 'history' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/history` TS7016
2 | import './_index.scss';
3 | import store from '../../store';
> 4 | import { History } from 'history';
| ^
This is the package.json:
{
"private": false,
"dependencies": {
"axios": "^0.19.2",
"bootstrap": "^4.6.0",
"history": "^4.10.1",
"identity-obj-proxy": "^3.0.0",
"react": "~17.0.1",
"react-app-polyfill": "~2.0.0",
"react-dom": "~17.0.1",
"react-router-dom": "~5.2.0"
},
Looks like the library "history" is causing the problem.
I tried:
Nothing seems to work.
Upvotes: 6
Views: 15080
Reputation: 1578
Assuming its as common package you would install your package and the type declarations
npm install history
npm install --save-dev @types/history
and include the types in your project within the tsconfig compilerOptions -
"typeRoots": [
"./node_modules/@types"
],
"types": ["history"]
Upvotes: 0
Reputation: 183
Looks like the new history
needs a dependency library @types/history
. I did a npm i @types/[email protected]
and then did a npm i
again. This fixed my problem.
Upvotes: 4
Reputation: 749
the problem seems to be from the history
package that you are using
Could not find a declaration file for module 'history'.
try installing types for the package
npm i @types/history
if that didn't work, then change the import to require
const history = require("history")
the @types/history
is deprecated and since version 5 of history
, the type declarations are provided inside the package itself.
updating the package should fix the issue:
npm install history@latest
Upvotes: 3