我想使用Typescript path aliases导入模块。现在我进口如下。
import { resourcePermissions } from '../../utils/resource-permissions';
import { allRoleAuthDetails } from '../../utils/autherize-details';我想要修改如下
import { resourcePermissions } from '@fboutil/resource-permissions';
import { allRoleAuthDetails } from '@fboutil/autherize-details';我更新了我的tsconfig.json文件如下
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "@loopback/build/config/tsconfig.common.json",
"compilerOptions": {
"rootDir": "./",
"module": "commonjs",
"noImplicitAny": true,
"target": "es2017",
"outDir": "dist",
"sourceMap": true,
"baseUrl": ".",
"moduleResolution": "node",
"removeComments": true,
"typeRoots": [
"node_modules/@types"
],
"paths": {
"@fboutil/*": [
"src/utils/*"
],
"*": [
"node_modules/@types/*",
"src/types/*"
]
}
},
"include": [
"src"
]
}代码在VSCode编辑器中没有显示任何错误。此外,我还可以通过导入行上的CNTRL+Click导航到模块文件。但是,在运行应用程序时,它会引发以下错误
Cannot start the application. Error: Cannot find module '@fbosutil/autherize-details'
Require stack:
- ......./dist/controllers/user.controller.js
- ......./node_modules/@loopback/boot/dist/booters/booter-utils.js
- ......./node_modules/@loopback/boot/dist/booters/base-artifact.booter.js
- ......./node_modules/@loopback/boot/dist/booters/index.js
- ......./node_modules/@loopback/boot/dist/boot.component.js
- ......./node_modules/@loopback/boot/dist/index.js
- ......./dist/application.js
- ......./dist/server.js
- ......./dist/index.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:94:18)express项目也是如此。当我使用循环-4时,它会抛出上面的错误。请帮助解决这个问题。
发布于 2022-08-09 01:36:34
但是,如果您使用"node /index.js“运行应用程序,您可能会看到一个类似于此错误的错误:无法找到模块‘@模块/示例/模型’--在这种情况下,您必须用tsc-别名替换构建中的所有相对路径。
您可以在这里找到更多详细信息:https://nextjsvietnam.com/post/how-to-use-typescript-path-alias-in-loopback-4/
https://stackoverflow.com/questions/69771963
复制相似问题