echoing-zebra-28421
06/09/2021, 8:53 PMpulumi up -y -s dev
my error TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Array
this is my tsconfig.ts
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@application/*": [
"application/*"
],
"@config/*": [
"config/*"
],
"@domain/*": [
"domain/*"
],
"@api-route": [
"api-route.ts"
],
"@interfaces/*": [
"interfaces/*"
]
},
"strict": true,
"outDir": "bin",
"target": "ESNEXT",
"lib": [
"ESNEXT"
],
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"typeRoots": [
"./node_modules/@types"
],
"types": [
"@types/node",
"node"
]
},
"files": [
"src/handler.ts"
],
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}
my package.json
{
"name": "api-notifications",
"scripts": {
"lint": "tslint -p tsconfig.json -c tslint.json",
"prettify": "prettier . --write"
},
"main": "src/handler.ts",
"devDependencies": {
"@types/aws-sdk": "^2.7.0",
"@types/dotenv": "^8.2.0",
"@types/node": "^10.17.60",
"typescript": "^4.2.4",
"tslint": "^6.1.3",
"tslint-config-airbnb": "^5.11.2"
},
"_moduleAliases": {
"@application": [
"bin/application"
],
"@config": [
"bin/config"
],
"@domain": [
"bin/domain"
],
"@interfaces": [
"bin/interfaces"
]
},
"dependencies": {
"@pulumi/aws": "^4.0.0",
"@pulumi/awsx": "^0.30.0",
"@pulumi/pulumi": "^3.0.0",
"@types/aws-lambda": "^8.10.76",
"axios": "^0.21.1",
"dotenv": "^9.0.2",
"module-alias": "^2.2.2"
}
}
Any idea or example to add the path aliases?
for example:
instead of this
import { CustomEventService } from "../../../application/services/custom-event/custom-event.service";
use this:
import { CustomEventService } from "@application/services/custom-event/custom-event.service";
in my ./src/handler.ts
I add
import "module-alias/register";
little-cartoon-10569
06/09/2021, 9:32 PM"module": "commonjs"
. The Pulumi files that the spec files import work fine with aliases.import { x } from "@mymodule";
in my .ts files, but I need import { x } from "../../../../src/resources/mymodule";
in my .spec.ts files.echoing-zebra-28421
06/09/2021, 9:57 PM"_moduleAliases": {
"@application": "src/application",
"@config": "src/config",
"@domain": "src/domain",
"@interfaces": "src/interfaces",
"@api-route": "src/api-route"
},
little-cartoon-10569
06/09/2021, 9:58 PMechoing-zebra-28421
06/09/2021, 10:33 PM"module-alias": "^2.2.2"
little-cartoon-10569
06/09/2021, 10:39 PMmodule-alias/register
? Do you use require("module-alias")
in all your projects? I'm wondering if there's a way to do it using package.json or tsconfig.json.echoing-zebra-28421
06/09/2021, 11:02 PMnpm i --save module-alias
in the tsconfig.json
you define your paths:
In my case
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@application/*": ["application/*"],
"@config/*": ["config/*"],
"@domain/*": ["domain/*"],
"@api-route": ["api-route.ts"],
"@interfaces/*": ["interfaces/*"]
},
in the package.json
you define the _moduleAliases
in my case
"_moduleAliases": {
"@application": "src/application",
"@config": "src/config",
"@domain": "src/domain",
"@interfaces": "src/interfaces",
"@api-route": "src/api-route"
},
now in the index.ts
(in my case is handler.ts
) you add
import "module-alias/register";
little-cartoon-10569
06/09/2021, 11:02 PMechoing-zebra-28421
06/09/2021, 11:06 PMmy-project
-- src
-- index.ts
-- folder1
-- folder2
...
-- tsconfig.ts
...
little-cartoon-10569
06/09/2021, 11:21 PMcurved-pharmacist-41509
06/10/2021, 12:49 AMentry.ts
file which my package.json points to. it has
const path = require('path')
const tsConfig = require(__dirname + '/../../../tsconfig.base.json')
const tsConfigPaths = require('tsconfig-paths')
const args = {
baseUrl: path.resolve(__dirname + '/../../..'),
paths: tsConfig.compilerOptions.paths,
}
tsConfigPaths.register(args)
module.exports = require('./index')
little-cartoon-10569
06/10/2021, 12:54 AMcurved-pharmacist-41509
06/10/2021, 12:54 AMnx up --affected