webtorrent / webtorrent

⚡️ Streaming torrent client for the web

Home Page:https://webtorrent.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

import doesn't work from typescript project

uriva opened this issue · comments

What version of this package are you using?

2.1.27

What operating system, Node.js, and npm version?

node v20.3.1
npm 9.6.7

What happened?

trying to import from a typescript project does not work. getting ERR_REQUIRE_ESM

here's my tsconfig:

{
  "ts-node": {
    "experimentalSpecifierResolution": "node",
    "transpileOnly": true
  },
  "compilerOptions": {
    "esModuleInterop": true,
    "allowImportingTsExtensions": true,
    "noEmit": true
  }
}

pacakge json:

{
  "name": "my-app",
  "version": "1.0.0",
  "scripts": {
    "start": "ts-node src/index.ts",
    "test": "jest test"
  },
  "dependencies": {
    "webtorrent": "^2.1.27"
  },
  "devDependencies": {
    "@babel/preset-env": "^7.22.20",
    "@types/jest": "^29.5.5",
    "@types/webtorrent": "^0.109.3",
    "jest": "^29.7.0",
    "ts-jest": "^29.1.1",
    "ts-node": "^10.9.1",
    "typescript": "^5.2.2"
  }
}

if I set type: "module", then I get TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"

Are you willing to submit a pull request to fix this bug?

if I have the knowledge

got it to work using this

{
  "ts-node": { "esm": true },
  "compilerOptions": {
    "target": "ESNext",
    "module": "NodeNext",
    "allowImportingTsExtensions": true,
    "moduleResolution": "NodeNext",
    "noEmit": true,
    "esModuleInterop": true,
    "strict": true
  }
}