Description
Hello!
I was trying out nanoid in a TypeScript project and came across an issue when running the code through ts-node-dev
.
The setup
EDIT: Forgot to include I have Node 13.3.0 installed.
The issue occurs with nanoid version 3.0.2 when running ts-node-dev
.
Compilation with tsc
passes without error.
I was able to reproduce the issue with the following setup:
package.json
{
"private": true,
"name": "01-todo-list",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc",
"start": "ts-node-dev -r tsconfig-paths/register --respawn --no-notify --transpileOnly ./src/index.ts"
},
"keywords": [],
"author": "dstrekelj <[email protected]>",
"license": "IDGAF",
"devDependencies": {
"@types/node": "^13.11.1",
"ts-node-dev": "^1.0.0-pre.44",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.8.3"
},
"dependencies": {
"nanoid": "^3.0.2"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./build",
"strict": true,
"moduleResolution": "node",
"baseUrl": "./src",
"paths": {
"@app/*": ["*"]
}
},
"exclude": ["node_modules", "build", "__tests__"]
}
src/index.ts
import { nanoid } from "nanoid";
console.log(nanoid());
Afterwards:
npm install
npm run start
The issue
Here is the complete transcript:
Using ts-node version 8.8.2, typescript version 3.8.3
Error: No valid exports main found for 'F:\projects\ts\challenges\reproducible\node_modules\nanoid'
at resolveExportsTarget (internal/modules/cjs/loader.js:618:9)
at applyExports (internal/modules/cjs/loader.js:499:14)
at resolveExports (internal/modules/cjs/loader.js:548:12)
at Function.Module._findPath (internal/modules/cjs/loader.js:650:22)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:948:27)
at Function.Module._resolveFilename (F:\projects\ts\challenges\reproducible\node_modules\tsconfig-paths\lib\register.js:75:40)
at Function.Module._load (internal/modules/cjs/loader.js:854:27)
at Module.require (internal/modules/cjs/loader.js:1023:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (F:\projects\ts\challenges\reproducible\src\index.ts:1:1)
[ERROR] 18:39:55 Error: No valid exports main found for 'F:\projects\ts\challenges\reproducible\node_modules\nanoid'
Other information
After downgrading to nanoid 2.1.11 everything worked fine, though I had to install @types/nanoid to get completion.
Older 3.x versions throw the same error.
I'm thinking ts-node-dev
is at fault or something in my configuration, but seeing as how version 3.x is still fresh I figured it's worth to create an issue just to be safe.
Might be related to #205?