我正在尝试为我的应用程序中的私有JS库使用Typescript类型文件。
该库并不位于node_modules
中,它实际上位于src\assets\extlib\extlib.js
中,并且通过我的 angular.json 文件中的scripts
属性包含了该库。>
运行ng build --verbose
时收到以下错误消息:
ERROR in ./src/app/myapp-common/drawer/drawer.component.ts
Module not found: Error: Can't resolve 'src/extlib-types/ex-drawer' in 'C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\app\myapp-common\drawer'
resolve 'src/extlib-types/ex-drawer' in 'C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\app\myapp-common\drawer'
Parsed request is a module
using description file: C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\package.json (relative path: ./src/app/myapp-common/drawer)
Field 'browser' doesn't contain a valid alias configuration
resolve as module
looking for modules in C:/Workspaces/myapp/mywebapp.next/mywebappWeb/ClientApp/
using description file: C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\package.json (relative path: .)
Field 'browser' doesn't contain a valid alias configuration
using description file: C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\package.json (relative path: ./src/extlib-types/ex-drawer)
no extension
Field 'browser' doesn't contain a valid alias configuration
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\extlib-types\ex-drawer doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\extlib-types\ex-drawer.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\extlib-types\ex-drawer.tsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\extlib-types\ex-drawer.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\extlib-types\ex-drawer.js doesn't exist
as directory
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\extlib-types\ex-drawer doesn't exist
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\app\myapp-common\drawer\node_modules doesn't exist or is not a directory
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\app\myapp-common\node_modules doesn't exist or is not a directory
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\app\node_modules doesn't exist or is not a directory
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\node_modules doesn't exist or is not a directory
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\node_modules doesn't exist or is not a directory
C:\Workspaces\myapp\mywebapp.next\node_modules doesn't exist or is not a directory
C:\Workspaces\myapp\node_modules doesn't exist or is not a directory
C:\Workspaces\node_modules doesn't exist or is not a directory
C:\node_modules doesn't exist or is not a directory
looking for modules in C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\node_modules
using description file: C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\package.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
using description file: C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\package.json (relative path: ./node_modules/src/extlib-types/ex-drawer)
no extension
Field 'browser' doesn't contain a valid alias configuration
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\node_modules\src\extlib-types\ex-drawer doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\node_modules\src\extlib-types\ex-drawer.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\node_modules\src\extlib-types\ex-drawer.tsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\node_modules\src\extlib-types\ex-drawer.mjs doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\node_modules\src\extlib-types\ex-drawer.js doesn't exist
as directory
C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\node_modules\src\extlib-types\ex-drawer doesn't exist
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\extlib-types\ex-drawer]
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\extlib-types\ex-drawer.ts]
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\extlib-types\ex-drawer.tsx]
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\extlib-types\ex-drawer.mjs]
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\extlib-types\ex-drawer.js]
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\app\myapp-common\drawer\node_modules]
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\app\myapp-common\node_modules]
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\app\node_modules]
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\src\node_modules]
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\node_modules]
[C:\Workspaces\myapp\mywebapp.next\node_modules]
[C:\Workspaces\myapp\node_modules]
[C:\Workspaces\node_modules]
[C:\node_modules]
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\node_modules\src\extlib-types\ex-drawer]
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\node_modules\src\extlib-types\ex-drawer.ts]
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\node_modules\src\extlib-types\ex-drawer.tsx]
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\node_modules\src\extlib-types\ex-drawer.mjs]
[C:\Workspaces\myapp\mywebapp.next\mywebappWeb\ClientApp\node_modules\src\extlib-types\ex-drawer.js]
@ ./src/app/myapp-common/drawer/drawer.component.ts 3:0-52 55:42-50
@ ./src/app/myapp-common/myapp-common.module.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi ./src/main.ts
在我看来,它正在尝试寻找 ex-drawer.js 真正应该在其中寻找 extlib.js 的地方,此外,它还在{ {1}}和其他永远找不到的地方。
如何使它正常工作?在 Visual Studio Code 的Intellisense中似乎可以正常工作,但是在编译时会失败。
这是我相关的源文件片段:
mycomp.component.ts
node_modules
ex-drawer.d.ts
import { EXDrawer } from 'src/extlib-types/ex-drawer';
tsconfig.json
import {PolymerElement, html} from '@polymer/polymer/polymer-element.js';
declare class EXDrawer extends PolymerElement {
visible: boolean|null|undefined;
label: string|null|undefined;
position: string|null|undefined;
connectedCallback(): void;
_closeDrawer(): void;
_drawerStatus(): void;
}
declare global {
interface HTMLElementTagNameMap {
"ex-drawer": EXDrawer;
}
}