0

I writing a code in nestjs. I am using the when module (https://www.npmjs.com/package/when) in my project.

I am importing when module as follows

import { sequence } from "when/sequence";

but when I print the sequence. it gives value as undefined. for that reason, not able to use when a module in nestjs any idea here how to import and install node module in nestjs

1
  • the last release of this package was in 2017 lol I think you can replace it Commented Oct 26, 2021 at 21:30

2 Answers 2

1

Seems like when only compiles to CommonJs and AMD. Therefore, it doesn't allow the import .. from "..." syntax introduced in ES6.

You should import it is using require().

const sequence = require("when/sequence")
Sign up to request clarification or add additional context in comments.

2 Comments

same issue. I am using node 14.17.5. is there any other way here?
@SurajDalvi but you can use node 14.17.5 without using ESM. But if you want to use ESM, then read this nodejs.org/api/module.html#modulecreaterequirefilename
0
import { sequence } from "when/sequence.js";

or use dynamic imports to load CJS modules:

const { default: sequence } = await import("when/sequence.js");

Comments

Your Answer

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.