Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module when using aliases #11331

Open
Duskfall opened this issue Mar 26, 2024 · 1 comment
Open

Cannot find module when using aliases #11331

Duskfall opened this issue Mar 26, 2024 · 1 comment

Comments

@Duskfall
Copy link

I am having an issue on deployment when using alias with ts-node and typescript
This is my folder structure
image
Inside the main.ts I import a file like this
import { appConfig } from '@base/config/app';
and @base is defined in the tsconfig.json like this

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es6",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist",
    "rootDir": ".",
    "baseUrl": ".",
    "paths": {
      "*": ["node_modules/*"],
      "@base/*": ["src/*"],
      "@api/*": ["src/api/*"]
    },
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "resolveJsonModule": true
  },
  "include": ["src/**/*"]
}

I am getting this error

Cannot find module '/var/task/src/config/app'
Require stack:
- /var/task/src/main.js
- /var/task/api/index.js
Did you forget to add it to "dependencies" in `package.json`?
INIT_REPORT Init Duration: 281.56 ms	Phase: invoke	Status: error	Error Type: Runtime.ExitError
Error: Runtime exited with error: exit status 1

Locally it works, and also if I change it to be import { appConfig } from './config/app'; it also works.
How can I make this to work?
I use a util method to fix the aliases for the ts-node on top of the main.ts for the dev environment

import ModuleAlias from 'module-alias';

export function fixModuleAlias(dirName: string) {
  ModuleAlias.addAliases({
    '@base': dirName,
    '@api': dirName + '/api',
  });
}

Thanks in advance

@muuvmuuv
Copy link

I have the same, it is because vercel overrides the includes here I guess
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants