Closed kehiy closed 1 year ago
Nano ID 4.0 is ESM-only project. It works only with import
. I recommend moving your project to ESM. Or you can install npm install nanoid@3
instead.
but I'm using import now!
Are you using TypeScript? With wrong settings it will compile import
to require
.
yes! I think my ts config is problem😐
@ai it is not always an option to config like this:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "ES6",
"target": "es2017",
}
}
At least not when you are using NestJS. Because then you cannot import @nestjs/*
. What do you think? Should NestJS move away from commonjs too? Just asked out of curiosity.
Anyway, I tried this solution but it did not work too:
https://stackoverflow.com/a/73420399/8784518 e.x.
async function nanoidGenerator(length = 20) {
const { customAlphabet } = await import('nanoid');
return customAlphabet(PUBLIC_ID_SEED, length)();
}
I'm trying to import nanoid in ts like this:
but I get this error: