I updated to nanoid4 and began getting the following error:
[ERR_REQUIRE_ESM]: require() of ES Module [...]/node_modules/nanoid/index.js not supported. Instead change the require of index.js in [...]/signup_test.ts to a dynamic import() which is available in all CommonJS modules
This is the import it's complaining about:
import { customAlphabet } from 'nanoid'
This is the tsconfig file I'm using:
{
"ts-node": {
"files": true
},
"compilerOptions": {
"jsx": "react-jsx",
"types": [
"node",
"codeceptjs"
],
"experimentalDecorators": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "ES6",
"moduleResolution": "node",
"resolveJsonModule": true,
"incremental": true,
"target": "ESNext",
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
Unsure why it's broken
require('nanoid')
which isn't legal isnanoid
is an ESM module. So, perhaps your TypeScript compiler configuration is wrong. But, that's just a guess. Seeing the generated JS file would tell you more. – Waterproof