Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find type definition file for '@types'

so i'm building an ionic application for android and ios devices.

when i'm trying to build application in android with command 'ionic cordova build android --prod --release', it works fine in (on windows)

butt in ios with the same command (on mac), gives me this error:

10:35:55]  typescript error 
        Cannot find type definition file for '@types'. 

[10:35:55]  ionic-app-script task: "build" 
[10:35:55]  Error: Failed to transpile TypeScript 
Error: Failed to transpile TypeScript
at errorCheckProgram (/Users/zakaria/Desktop/untitled 
folder/transatour/node_modules/@ionic/app-scripts/dist/aot/aot- 
compiler.js:119:39)
at Object.<anonymous> (/Users/zakaria/Desktop/untitled 
folder/transatour/node_modules/@ionic/app-scripts/dist/aot/aot- 
compiler.js:89:21)
at step (/Users/zakaria/Desktop/untitled 
folder/transatour/node_modules/@ionic/app-scripts/dist/aot/aot- 
compiler.js:32:23)
at Object.next (/Users/zakaria/Desktop/untitled 
folder/transatour/node_modules/@ionic/app-scripts/dist/aot/aot- 
compiler.js:13:53)
at fulfilled (/Users/zakaria/Desktop/untitled 
folder/transatour/node_modules/@ionic/app-scripts/dist/aot/aot- 
compiler.js:4:58)
[ERROR] An error occurred while running subprocess ionic-app- 
scripts.

    ionic-app-scripts build --prod --target cordova --platform ios 
 exited with exit code 1.

    Re-running this command with the --verbose flag may provide 
more information.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build:prod:ios: `cross-env 
NODE_OPTIONS='- 
-max-old-space-size=8192' ionic cordova build ios --prod --release`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] build:prod:ios script.
npm ERR! This is probably not a problem with npm. There is likely 
additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/zakaria/.npm/_logs/2019-06-03T11_35_55_786Z- 
 debug.log
like image 212
Chawki Tazzi Avatar asked Jun 03 '19 11:06

Chawki Tazzi


People also ask

Can't find a module or its corresponding type declarations?

The "Cannot find module or its corresponding type declarations" error occurs when TypeScript cannot locate a third-party or local module in our project. To solve the error, make sure to install the module and try setting moduleResolution to node in your tsconfig. json file.

Could not find Type Definition File?

To solve the error "Cannot find type definition file for node", install the node types by running npm i -D @types/node . If the error is not resolved, try adding node to your types array in tsconfig. json and restarting your IDE.

Why does typescript assume the base name of the Type Definition File?

If the package.json file of the package does not explicitly specify the location of a type definition file, Typescript will assume that the type definition file has the same base name and location as the package's main module.

How to fix cannot find type definition file for node?

If that doesn't help, make sure the types array in your tsconfig.json file contains "node". Copied! That should fix the "Cannot find type definition file for node" error in your project. When the types option is specified, only the listed packages will be included in the global scope.

Why are my types not being specified in typescript?

Sorry, something went wrong. When types is not specified (this seems to be the case that mystifies the most users): Subdirectory ' {0}' of 'typeRoots' directory ' {1}' is not a valid types package. If the presence of this subdirectory is intentional, change the 'typeRoots' or 'types' option.

Is it an error if a typedef is missing or not?

This should probably be a warning rather than an error. A missing typedef is equivalent to an empty typedef, which isn't an error condition. Sorry, something went wrong.


Video Answer


2 Answers

This error showed up after upgrading @ionic/app-scripts: 3.2.3 to latest version 3.2.4.

I did not downgrade to fix it

I added

"types": [],

into

"compilerOptions"

in tsconfig.json file and the error was gone.

Now my tsconfig.json file looks like this:

"compilerOptions": {
    "types": [],  <== fix added here <==
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5"
  }
like image 83
faus Avatar answered Nov 01 '22 03:11

faus


Downgrade the @ionic/app-scripts version to 3.2.3 is worked for me.

 npm i @ionic/[email protected]
like image 31
Sakthimurugan Saravanan Avatar answered Nov 01 '22 01:11

Sakthimurugan Saravanan