2

I have a NestJS application with some commands attached to it. When I run the application I can import path as

import path from 'path';

and it will work fine.

When I use nest-command to run a CLI command, I get an error

Cannot read properties of undefined (reading 'join')

obviously referring to the path.join function

If I change it to

import * as path from 'path'

It works fine on the command but not in the main application!

What is the problem?

asked Jan 3, 2025 at 15:04

2 Answers 2

1

this has nothing to do with NestJS. This is due to how TypeScript works depending on your typescript compiler configuration (usually tsconfig.json file)

You can use import path from "node:path" if you have the esModuleInterop on. Otherwise (the default), you'll have to use import * as path from "node:path"

Read the typescript docs:

answered Jan 3, 2025 at 15:49
Sign up to request clarification or add additional context in comments.

Comments

0

Try using import * as path from 'node:path'

answered Jan 3, 2025 at 15:23

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.