The statement
x = $('#msgBox_' + scope.boxId).position().left;
generates an
error TS2304: Cannot find name '$'
although jquery
and @types
are installed in the node_modules folder.
My tsconfig.json looks like that:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"moduleResolution": "node",
"declaration": true
},
"exclude": [
"node_modules"
]
}
How can I fix that?
To solve the error "Cannot find name process", 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.
The Node runtime does not ship with its own type definitions, so we need to import those types separately. Where can we find them? They are also in npm but need to be installed separately.
To solve the "Cannot find module path or its corresponding type declarations" error, install the types for node by running the command npm i -D @types/node . You can then import path with the following line of code import * as path from 'path' .
AngularJS ng-required Directive The ng-required directive sets the required attribute of a form field (input or textarea). The form field will be required if the expression inside the ng-required attribute returns true. The ng-required directive is necessary to be able to shift the value between true and false .
If AngularCLI is where your injecting JQuery, then in your controller/component, you can declare the variable like so:
declare var $: any;
Did you try to :
import $ = require('jquery');
at the 1 line? This should work. Though you should have a deeper look into es6 modules and ts modules to get a grip on how you could take advantage of the es6 modular system. Also d.ts files...
This should be helpful: https://www.typescriptlang.org/docs/handbook/modules.html
Turns out I was missing the "@types/jquery" node module, which contains a definition of "$". Once I added "@types/jquery": "^3.2.5" to the list of "devDependencies" in my package.json and reinstalled via "npm install", everything worked fine.
One reason for this kind of error is your node_modules doesn't contain the type definitions for jquery ie. the package @types/jquery
is missing.
My workaround is as follows:
Open the command prompt in the root of your project folder and type:
npm install --save @types/jquery
.
If you are posed with a question to choose the version, choose the latest one.
Once the above command ends successfully, run yarn install
.
Once the above install is success, run yarn start
to start your project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With