typescript(ng2)中使用nodejs模块的方法
来源:互联网 发布:天启小米抢购软件 编辑:程序博客网 时间:2024/06/05 04:32
angular2项目需要调用外部nodejs模块,没有ts版本,记录一下方法
转载自:https://stackoverflow.com/questions/31173738/typescript-getting-error-ts2304-cannot-find-name-require
TypeScript 2.x
If you are using TypeScript 2.x you no longer need to have Typings or Definitely Typed installed. Simply install the following package.
npm install @types/node --save-dev
The Future of Declaration Files (6/15/2016)
Tools like Typings and tsd will continue to work, and we’ll be working alongside those communities to ensure a smooth transition.
OPTIONAL: If you are specifying typeroots
or types
in your tsconfig.json
. You may need to update the tsconfig.json
to include node as a type. By default any package under @types is already included in your build unless you've specified either of these options. Read more
Below is proper configuration for each of these options.
{ "compilerOptions": { // types option has been previously configured "types": [ // add node as an option "node" ], // typeRoots option has been previously configured "typeRoots": [ // add path to @types "node_modules/@types" ] }}
TypeScript 1.x
Using typings (DefinitelyTyped's replacement) you can specify a definition directly from a GitHub repository.
Install typings
npm install typings -g --save-dev
Install the requireJS type definition from DefinitelyType's repo
typings install dt~node --save --global
Quick and Dirty
If you just have one file using require, or you're doing this for demo purposes you can define require at the top of your TypeScript file.
declare var require: any
Angular CLI
If you're attempting to use a require
statement in your Angular CLI project, update tsconfig.app.json
to include node typings.
"compilerOptions": { // other options "types": [ "node" ] }
- typescript(ng2)中使用nodejs模块的方法
- nodejs中的方法和模块的使用
- nodejs 中模块使用的介绍
- 在Java项目中拥抱Nodejs — 使用gruntjs编译typescript,并将生成的js合并、压缩
- nodejs--underscore模块的使用
- 使用TypeScript 搜索JSON的简单方法
- typescript中import"fs"模块
- nodeJs中系统模块的常用方法和自定义模块暴露
- 使用vscode 搭建 typescript 的nodejs 自动编译自动启动服务
- nodejs中request模块proxy的使用方法
- NodeJS基础:exports模块的使用
- NodeJS基础:querystring 模块的使用
- NodeJS基础:readline模块的使用
- nodejs中使用多线程编程的方法实例
- NodeJS模块导出使用
- nodejs debug 模块使用
- nodejs加密模块使用
- 在Meteor中调用NodeJS模块或者自己的模块
- 贝叶斯定理与贝叶斯估计
- ES6--变量的解构赋值
- MapReduce的运行
- POJ
- Matlab使用技巧 (如何提取文档数据和表格数据)
- typescript(ng2)中使用nodejs模块的方法
- maven 常用的一些命令
- #228. 噼里啪啦
- Qt显示本地语言(支持中文问题)
- Django框架下用户注册邮箱验证功能的实现
- 2017.9.24
- Python 修改内存地址
- BIM技术
- 基于matlab的SMO实现