Angular找不到自定义库的模块
我在angular应用程序中实现SSR,同时尝试运行Angular找不到自定义库的模块,angular,typescript,server-side-rendering,angular-universal,Angular,Typescript,Server Side Rendering,Angular Universal,我在angular应用程序中实现SSR,同时尝试运行npm run build:SSR它抛出以下错误 我已经创建了自己的LIB,它是否捆绑在dist文件夹中,名称为@asfc/shared ERROR in projects/asfc-web/src/environments/environment.ts:1:39 - error TS2307: Cannot find module '@asfc/shared' or its corresponding type declarations.
npm run build:SSR
它抛出以下错误
我已经创建了自己的LIB,它是否捆绑在dist文件夹中,名称为@asfc/shared
ERROR in projects/asfc-web/src/environments/environment.ts:1:39 - error TS2307: Cannot find module '@asfc/shared' or its corresponding type declarations.
1 import { PageNotFoundComponent } from '@asfc/shared';
~~~~~~~~~~~~~~
......
我已经将index.ts添加到文件中
,但错误仍然没有消失
下面是我的,tsconfig.server.json
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"removeComments": false,
"strict": false,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitAny": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"experimentalDecorators": true,
"pretty": true,
"declaration": true,
"outDir": "../../dist/server",
"lib": ["es2016", "DOM"],
"types": [
"node"
],
"typeRoots": [
"node_modules/@types"
]
},
"files": [
"server.ts",
"../../dist/asfc-shared/public_api.d.ts"
],
"angularCompilerOptions": {
"entryModule": "../../projects/asfc-web/src/app/app.server.module.ts#AppServerModule"
},
"exclude": [
"node_modules",
"dist"
]
}
"compilerOptions": {
....
"paths": {
"@asfc/shared/*": [
"../../dist/asfc-shared/*"
],
}
},
下面是我的Dist Libs结构
dist/asfc-shared
├── asfc-shared.d.ts
├── package.json
├── public_api.d.ts
请提供帮助。尝试在
tsconfig.json中添加路径映射
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"removeComments": false,
"strict": false,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitAny": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"experimentalDecorators": true,
"pretty": true,
"declaration": true,
"outDir": "../../dist/server",
"lib": ["es2016", "DOM"],
"types": [
"node"
],
"typeRoots": [
"node_modules/@types"
]
},
"files": [
"server.ts",
"../../dist/asfc-shared/public_api.d.ts"
],
"angularCompilerOptions": {
"entryModule": "../../projects/asfc-web/src/app/app.server.module.ts#AppServerModule"
},
"exclude": [
"node_modules",
"dist"
]
}
"compilerOptions": {
....
"paths": {
"@asfc/shared/*": [
"../../dist/asfc-shared/*"
],
}
},
您的配置中还排除了dist
文件夹,但我想这与包含lib的文件夹不同。尝试在tsconfig.json中添加路径映射
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"removeComments": false,
"strict": false,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitAny": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"experimentalDecorators": true,
"pretty": true,
"declaration": true,
"outDir": "../../dist/server",
"lib": ["es2016", "DOM"],
"types": [
"node"
],
"typeRoots": [
"node_modules/@types"
]
},
"files": [
"server.ts",
"../../dist/asfc-shared/public_api.d.ts"
],
"angularCompilerOptions": {
"entryModule": "../../projects/asfc-web/src/app/app.server.module.ts#AppServerModule"
},
"exclude": [
"node_modules",
"dist"
]
}
"compilerOptions": {
....
"paths": {
"@asfc/shared/*": [
"../../dist/asfc-shared/*"
],
}
},
您的配置中还排除了dist
文件夹,但我想这与包含lib的文件夹不一样