angularjs – 具有打字稿的量角器在成功解决后无法找到模块’量
发布时间:2020-12-17 17:08:26 所属栏目:安全 来源:网络整理
导读:这个问题让我很难过.请帮忙. 我有以下文件结构: node_modules protractor typescriptpackage.jsonregister-popup.ts package.json的内容 { "name": "typescriptProba","version": "1.0.0","description": "","main": "index.js","scripts": { "test": "echo
这个问题让我很难过.请帮忙.
我有以下文件结构: node_modules protractor typescript package.json register-popup.ts package.json的内容 { "name": "typescriptProba","version": "1.0.0","description": "","main": "index.js","scripts": { "test": "echo "Error: no test specified" && exit 1" },"keywords": [],"author": "","license": "ISC","dependencies": { "protractor": "^4.0.11","typescript": "^2.0.10" } } register-popup.ts的内容: import { ElementFinder,element,by } from "protractor"; export class RegisterPopup { public registerWithFacebookButton: ElementFinder = element(by.css('li.facebook a')); public registerWithGoogleButton: ElementFinder = element(by.css('li.google a')); public registerWithEmailButton: ElementFinder = element(by.css('li.email a')); public registerWithMobileButton: ElementFinder = element(by.css('li.natel a')); constructor () {} openPopup() { element(by.css('.account.user')).click(); element(by.id('openRegister')).click(); } openRegisterByEmailPopup() { this.registerWithEmailButton.click(); } openRegisterByPhonePopup() { this.registerWithMobileButton.click(); } } 为了将ts文件编译为js文件,我使用以下命令: ./node_modules/typescript/bin/tsc "./register-popup.ts" --module commonjs --noResolve --traceResolution 执行命令后,我有以下错误: error TS2307: Cannot find module 'protractor'. 但我的模块跟踪分辨率是这样的: ======== Resolving module 'protractor' from '/Users/predraglazarevic/www/typescriptProba/register-popup.ts'. ======== Module resolution kind is not specified,using 'NodeJs'. Loading module 'protractor' from 'node_modules' folder. File '/Users/predraglazarevic/www/typescriptProba/node_modules/protractor.ts' does not exist. File '/Users/predraglazarevic/www/typescriptProba/node_modules/protractor.tsx' does not exist. File '/Users/predraglazarevic/www/typescriptProba/node_modules/protractor.d.ts' does not exist. Found 'package.json' at '/Users/predraglazarevic/www/typescriptProba/node_modules/protractor/package.json'. 'package.json' has 'typings' field 'built/index.d.ts' that references '/Users/predraglazarevic/www/typescriptProba/node_modules/protractor/built/index.d.ts'. File '/Users/predraglazarevic/www/typescriptProba/node_modules/protractor/built/index.d.ts' exist - use it as a name resolution result. Resolving real path for '/Users/predraglazarevic/www/typescriptProba/node_modules/protractor/built/index.d.ts',result '/Users/predraglazarevic/www/typescriptProba/node_modules/protractor/built/index.d.ts' ======== Module name 'protractor' was successfully resolved to '/Users/predraglazarevic/www/typescriptProba/node_modules/protractor/built/index.d.ts'. ======== 所以我有
但仍然有错误
为什么? 回答 当我省略–noResolve标志时,它正在工作.所以命令应该是 ./node_modules/typescript/bin/tsc "./register-popup.ts" --module commonjs 解决方法
首先,您需要检查tsconfig.json,您会看到typeRoots
{ "compileOnSave": false,"compilerOptions": { "declaration": false,"emitDecoratorMetadata": true,"experimentalDecorators": true,"lib": [ "es2016" ],"module": "commonjs","moduleResolution": "node","outDir": "path/to/transpiled/files","sourceMap": true,"target": "es6","typeRoots": [ "node_modules/@types" ] } } 如果您有任何其他DefinitelyTyped模块,它们将被本地路径中的typeRoots目录选取:node_modules / @ types. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Docker永远在“Docker正在开始……”的Windows任务中
- 除了<和>标记外,Vim还用于恢复'gv'上的视觉选择?
- angularjs – Angular UI Bootstrap Alert Closable Issue
- scala – 如何在不同配置中将SBT用于相互依赖的项目
- 单元测试 – 单元测试Angular 2 authGuard;间谍方法没有被调
- 完成后,vim需要很长时间才能扫描标签
- angularjs – 如何捕获无效的URL?
- typescript – 使用angular2 rc4将所有无效URL重定向到特定
- bash – 如何在shell脚本中调用ioctl?
- icons – 如何设置应用程序图标为Electron/Atom Shell App