TypeStrong / ts-node

TypeScript execution and REPL for node.js
https://typestrong.org/ts-node
MIT License
12.93k stars 532 forks source link

TypeError: value.replace is not a function on yarn 4.5.1, Node.js v20.13.1 #2141

Open ridhwaans opened 3 weeks ago

ridhwaans commented 3 weeks ago

Search Terms

Expected Behavior

I expect ts-node to run src/index.ts without errors

Actual Behavior

yarn run dotenv -e ../web/.env.local -- ts-node src/index.ts
/home/ridhwaans/Source/test/.yarn/__virtual__/ts-node-virtual-c211acd0da/3/.yarn/berry/cache/ts-node-npm-10.9.2-3f3890b9ac-10c0.zip/node_modules/ts-node/dist/util.js:62
    return value.replace(backslashRegExp, directorySeparator);
                 ^

TypeError: value.replace is not a function
    at normalizeSlashes (/home/ridhwaans/Source/test/.yarn/__virtual__/ts-node-virtual-c211acd0da/3/.yarn/berry/cache/ts-node-npm-10.9.2-3f3890b9ac-10c0.zip/node_modules/ts-node/dist/util.js:62:18)
    at Object.getExtendsConfigPath (/home/ridhwaans/Source/test/.yarn/__virtual__/ts-node-virtual-c211acd0da/3/.yarn/berry/cache/ts-node-npm-10.9.2-3f3890b9ac-10c0.zip/node_modules/ts-node/dist/ts-internals.js:24:54) 
    at readConfig (/home/ridhwaans/Source/test/.yarn/__virtual__/ts-node-virtual-c211acd0da/3/.yarn/berry/cache/ts-node-npm-10.9.2-3f3890b9ac-10c0.zip/node_modules/ts-node/dist/configuration.js:127:64)
    at findAndReadConfig (/home/ridhwaans/Source/test/.yarn/__virtual__/ts-node-virtual-c211acd0da/3/.yarn/berry/cache/ts-node-npm-10.9.2-3f3890b9ac-10c0.zip/node_modules/ts-node/dist/configuration.js:50:84)
    at phase3 (/home/ridhwaans/Source/test/.yarn/__virtual__/ts-node-virtual-c211acd0da/3/.yarn/berry/cache/ts-node-npm-10.9.2-3f3890b9ac-10c0.zip/node_modules/ts-node/dist/bin.js:254:67)
    at bootstrap (/home/ridhwaans/Source/test/.yarn/__virtual__/ts-node-virtual-c211acd0da/3/.yarn/berry/cache/ts-node-npm-10.9.2-3f3890b9ac-10c0.zip/node_modules/ts-node/dist/bin.js:47:30)
    at main (/home/ridhwaans/Source/test/.yarn/__virtual__/ts-node-virtual-c211acd0da/3/.yarn/berry/cache/ts-node-npm-10.9.2-3f3890b9ac-10c0.zip/node_modules/ts-node/dist/bin.js:33:12)
    at Object.<anonymous> (/home/ridhwaans/Source/test/.yarn/__virtual__/ts-node-virtual-c211acd0da/3/.yarn/berry/cache/ts-node-npm-10.9.2-3f3890b9ac-10c0.zip/node_modules/ts-node/dist/bin.js:579:5)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)

Node.js v20.13.1

Steps to reproduce the problem

  1. Install yarn 4.5.1 (berry)
  2. yarn add ts-node --dev
  3. Install dotenv
  4. copy the src/index.ts, tsup and ts-node configs
  5. Run `yarn run dotenv -e ../web/.env.local -- ts-node src/index.ts
//tsup.config.ts
import { defineConfig } from 'tsup';

export default defineConfig((opts) => ({
  entry: ['./src/index.ts'],
  format: ['cjs'], // CommonJS format
  splitting: false, // Avoid splitting
  sourcemap: true,
  minify: !opts.watch,
  clean: !opts.watch,
  dts: true,
  outDir: 'dist',
  esbuildOptions: (options) => {
    options.external = ['path', 'fs', 'os']; // Mark Node.js built-in modules as external
    options.platform = 'node'; // Ensure the target platform is Node.js
  },
}));

Minimal reproduction

Specifications

//tsconfig.json
{
  "extends": ["@project/tsconfig/base.json"],
  "compilerOptions": {
    "tsBuildInfoFile": ".tsbuildinfo",
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "include": ["**/*.ts", "**/*.js"]
}

* Operating system and version:
* If Windows, are you using WSL or WSL2?:
Pasha28198 commented 3 weeks ago

Try to update tsconfig.json with these changes from extends: ['...'] to extends: '...'