parser-ts icon indicating copy to clipboard operation
parser-ts copied to clipboard

Import path problem in using ESM feature typescript@next

Open oocytanb opened this issue 4 years ago • 0 comments

🐛 Bug report

Current Behavior

I am trying to build ECMAScript modules (ESM) that is supported by TypeScript nightly build.

https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta/

tsc fails in *.mts (new source file extension for ESM) that imports parser-ts module.

Error log:

node_modules/parser-ts/lib/Parser.d.ts(7,27): error TS2307: Cannot find module 'fp-ts/ChainRec' or its corresponding type declarations.
node_modules/parser-ts/lib/Parser.d.ts(410,16): error TS2665: Invalid module name in augmentation. Module 'fp-ts/lib/HKT' resolves to an untyped module at 'node_modules/fp-ts/lib/HKT/index.js', which cannot be augmented.
node_modules/parser-ts/lib/Parser.d.ts(429,40): error TS2344: Type '"Parser"' does not satisfy the constraint 'keyof URItoKind2<any, any>'.
node_modules/parser-ts/lib/Parser.d.ts(434,48): error TS2344: Type '"Parser"' does not satisfy the constraint 'keyof URItoKind2<any, any>'.
node_modules/parser-ts/lib/Parser.d.ts(439,36): error TS2344: Type '"Parser"' does not satisfy the constraint 'keyof URItoKind2<any, any>'.
node_modules/parser-ts/lib/Parser.d.ts(449,32): error TS2344: Type '"Parser"' does not satisfy the constraint 'keyof URItoKind2<any, any>'.
node_modules/parser-ts/lib/Parser.d.ts(454,48): error TS2344: Type '"Parser"' does not satisfy the constraint 'keyof URItoKind2<any, any>'.
node_modules/parser-ts/lib/Parser.d.ts(459,37): error TS2344: Type '"Parser"' does not satisfy the constraint 'keyof URItoKind2<any, any>'.
node_modules/parser-ts/lib/Parser.d.ts(459,57): error TS2344: Type '"Parser"' does not satisfy the constraint 'keyof URItoKind2<any, any>'.
node_modules/parser-ts/lib/string.d.ts(6,33): error TS7016: Could not find a declaration file for module 'fp-ts/lib/HKT'. 'node_modules/fp-ts/lib/HKT/index.js' implicitly has an 'any' type.
  If the 'fp-ts' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'fp-ts/lib/HKT';`

Expected behavior

tsc succeeds.

Reproducible example

main.mts

import { parser as P, string as S } from 'parser-ts';
console.log(P, S);

tsconfig.json

{
  "compilerOptions": {
    "strict": true,
    "module": "nodenext",
  }
}

package.json

{
  "name": "test_esm",
  "type": "module",
  "devDependencies": {
    "typescript": "^4.6.0-dev.20211113"
  },
  "dependencies": {
    "fp-ts": "^2.11.5",
    "parser-ts": "^0.6.16"
  },
  "scripts": {
    "build": "tsc"
  }
}

Suggested solution(s)

This issue seems to be fixable by change the import path.

  • 'fp-ts/ChainRec' to 'fp-ts/lib/ChainRec'
  • 'fp-ts/lib/HKT' to 'fp-ts/HKT'

Additional context

Your environment

Which versions of parser-ts are affected by this issue? Did this work in previous versions of parser-ts?

Software Version(s)
fp-ts 2.11.5
parser-ts 0.6.16
TypeScript next

oocytanb avatar Nov 13 '21 10:11 oocytanb