Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

require('ipfs-core') in ipfs package causes invalid typedef genration. #3358

Closed
Gozala opened this issue Oct 27, 2020 · 5 comments
Closed

require('ipfs-core') in ipfs package causes invalid typedef genration. #3358

Gozala opened this issue Oct 27, 2020 · 5 comments
Labels
need/triage Needs initial labeling and prioritization

Comments

@Gozala
Copy link
Contributor

Gozala commented Oct 27, 2020

We had to workaround the fact that following line:

const IPFS = require('ipfs-core')

produces dist/src/index.d.ts like

declare const IPFS: typeof import("ipfs-core/src");

Which then TS seems to fail to resolve, by changing require path to ipfs-core/src (see #3356)

We should figure out what is going on there and find a proper fix for that workaround.

@Gozala Gozala added the need/triage Needs initial labeling and prioritization label Oct 27, 2020
@Gozala
Copy link
Contributor Author

Gozala commented Oct 27, 2020

I have setup an example TS project that pulls in the ipfs@next to try and figure this problem out. Running tsc --noEmit --traceResolution seems to suggest that TS attempts to look for node_modules/ipfs-core/dist/src as all the file types bun never as a directory (belowe is the relevant bits and noice removed

Loading module 'ipfs-core/src' from 'node_modules' folder, target file type 'TypeScript'.
...
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src.ts' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src.tsx' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src.d.ts' does not exist.

But then TS seems to do something strange when trying to resolve as directory

'package.json' has 'main' field 'src/index.js' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src/src/index.js'.
'package.json' has a 'typesVersions' entry '*' that matches compiler version '4.0.3', looking for a pattern to match module name 'src/index.js'.
Module name 'src/index.js', matched pattern '*'.
Trying substitution 'dist/*', candidate module location: 'dist/src/index.js'.
Loading module as file / folder, candidate module location '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src/dist/src/index.js', target file type 'TypeScript'.
File name '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src/dist/src/index.js' has a '.js' extension - stripping it.

And for some reason it never tries .ts, .d.ts extensions there, and just walks up the directory tree

Directory '/Users/gozala/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name 'ipfs-core/src' was not resolved. ========
Full output log
======== Resolving module 'ipfs' from '/Users/gozala/Projects/ipfs-ts-use/src/main.ts'. ========
Module resolution kind is not specified, using 'NodeJs'.
Loading module 'ipfs' from 'node_modules' folder, target file type 'TypeScript'.
Directory '/Users/gozala/Projects/ipfs-ts-use/src/node_modules' does not exist, skipping all lookups in it.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/package.json'.
'package.json' has a 'typesVersions' field with version-specific path mappings.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs.ts' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs.tsx' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs.d.ts' does not exist.
'package.json' does not have a 'typings' field.
'package.json' does not have a 'types' field.
'package.json' has 'main' field 'src/index.js' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/src/index.js'.
'package.json' has a 'typesVersions' entry '*' that matches compiler version '4.0.3', looking for a pattern to match module name 'src/index.js'.
Module name 'src/index.js', matched pattern '*'.
Trying substitution 'dist/*', candidate module location: 'dist/src/index.js'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/index.js' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/index.js' does not exist.
Loading module as file / folder, candidate module location '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/index.js', target file type 'TypeScript'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/index.js.ts' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/index.js.tsx' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/index.js.d.ts' does not exist.
File name '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/index.js' has a '.js' extension - stripping it.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/index.ts' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/index.tsx' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/index.d.ts', result '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/index.d.ts'.
======== Module name 'ipfs' was successfully resolved to '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/index.d.ts' with Package ID 'ipfs/dist/src/index.d.ts@0.50.3-rc.29'. ========
======== Resolving module 'ipfs-core/src' from '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/index.d.ts'. ========
Module resolution kind is not specified, using 'NodeJs'.
Loading module 'ipfs-core/src' from 'node_modules' folder, target file type 'TypeScript'.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/node_modules' does not exist, skipping all lookups in it.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/src/package.json' does not exist.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/package.json'.
'package.json' has a 'typesVersions' field with version-specific path mappings.
'package.json' has a 'typesVersions' entry '*' that matches compiler version '4.0.3', looking for a pattern to match module name 'src'.
Module name 'src', matched pattern '*'.
Trying substitution 'dist/*', candidate module location: 'dist/src'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src.ts' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src.tsx' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src.d.ts' does not exist.
'package.json' does not have a 'typings' field.
'package.json' does not have a 'types' field.
'package.json' has 'main' field 'src/index.js' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src/src/index.js'.
'package.json' has a 'typesVersions' entry '*' that matches compiler version '4.0.3', looking for a pattern to match module name 'src/index.js'.
Module name 'src/index.js', matched pattern '*'.
Trying substitution 'dist/*', candidate module location: 'dist/src/index.js'.
Loading module as file / folder, candidate module location '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src/dist/src/index.js', target file type 'TypeScript'.
File name '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src/dist/src/index.js' has a '.js' extension - stripping it.
Directory '/Users/gozala/Projects/node_modules/@types' does not exist, skipping all lookups in it.
Directory '/Users/gozala/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
Loading module 'ipfs-core/src' from 'node_modules' folder, target file type 'JavaScript'.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/src/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/dist/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs/node_modules' does not exist, skipping all lookups in it.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/src/package.json' does not exist.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/package.json'.
'package.json' has a 'typesVersions' field with version-specific path mappings.
'package.json' has a 'typesVersions' entry '*' that matches compiler version '4.0.3', looking for a pattern to match module name 'src'.
Module name 'src', matched pattern '*'.
Trying substitution 'dist/*', candidate module location: 'dist/src'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src.js' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src.jsx' does not exist.
'package.json' has 'main' field 'src/index.js' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src/src/index.js'.
'package.json' has a 'typesVersions' entry '*' that matches compiler version '4.0.3', looking for a pattern to match module name 'src/index.js'.
Module name 'src/index.js', matched pattern '*'.
Trying substitution 'dist/*', candidate module location: 'dist/src/index.js'.
Loading module as file / folder, candidate module location '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src/dist/src/index.js', target file type 'JavaScript'.
File name '/Users/gozala/Projects/ipfs-ts-use/node_modules/ipfs-core/dist/src/dist/src/index.js' has a '.js' extension - stripping it.
Directory '/Users/gozala/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name 'ipfs-core/src' was not resolved. ========
======== Resolving type reference directive 'bl', containing file '/Users/gozala/Projects/ipfs-ts-use/__inferred type names__.ts', root directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'. ========
Resolving with primary search path '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bl/package.json'.
'package.json' does not have a 'typesVersions' field.
'package.json' does not have a 'typings' field.
'package.json' does not have a 'types' field.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bl/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bl/index.d.ts', result '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bl/index.d.ts'.
======== Type reference directive 'bl' was successfully resolved to '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bl/index.d.ts' with Package ID '@types/bl/index.d.ts@2.1.0', primary: true. ========
======== Resolving type reference directive 'bn.js', containing file '/Users/gozala/Projects/ipfs-ts-use/__inferred type names__.ts', root directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'. ========
Resolving with primary search path '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bn.js/package.json'.
'package.json' does not have a 'typesVersions' field.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field 'index.d.ts' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bn.js/index.d.ts'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bn.js/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bn.js/index.d.ts', result '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bn.js/index.d.ts'.
======== Type reference directive 'bn.js' was successfully resolved to '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bn.js/index.d.ts' with Package ID '@types/bn.js/index.d.ts@4.11.6', primary: true. ========
======== Resolving type reference directive 'debug', containing file '/Users/gozala/Projects/ipfs-ts-use/__inferred type names__.ts', root directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'. ========
Resolving with primary search path '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/debug/package.json'.
'package.json' does not have a 'typesVersions' field.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field 'index' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/debug/index'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/debug/index' does not exist.
Loading module as file / folder, candidate module location '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/debug/index', target file type 'TypeScript'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/debug/index.ts' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/debug/index.tsx' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/debug/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/debug/index.d.ts', result '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/debug/index.d.ts'.
======== Type reference directive 'debug' was successfully resolved to '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/debug/index.d.ts' with Package ID '@types/debug/index.d.ts@4.1.5', primary: true. ========
======== Resolving type reference directive 'long', containing file '/Users/gozala/Projects/ipfs-ts-use/__inferred type names__.ts', root directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'. ========
Resolving with primary search path '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/long/package.json'.
'package.json' does not have a 'typesVersions' field.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field 'index.d.ts' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/long/index.d.ts'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/long/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/long/index.d.ts', result '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/long/index.d.ts'.
======== Type reference directive 'long' was successfully resolved to '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/long/index.d.ts' with Package ID '@types/long/index.d.ts@4.0.1', primary: true. ========
======== Resolving type reference directive 'node', containing file '/Users/gozala/Projects/ipfs-ts-use/__inferred type names__.ts', root directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'. ========
Resolving with primary search path '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/package.json'.
'package.json' does not have a 'typesVersions' field.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field 'index.d.ts' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts', result '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts'.
======== Type reference directive 'node' was successfully resolved to '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts' with Package ID '@types/node/index.d.ts@8.10.65', primary: true. ========
======== Resolving type reference directive 'pbkdf2', containing file '/Users/gozala/Projects/ipfs-ts-use/__inferred type names__.ts', root directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'. ========
Resolving with primary search path '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/pbkdf2/package.json'.
'package.json' does not have a 'typesVersions' field.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field 'index.d.ts' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/pbkdf2/index.d.ts'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/pbkdf2/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/pbkdf2/index.d.ts', result '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/pbkdf2/index.d.ts'.
======== Type reference directive 'pbkdf2' was successfully resolved to '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/pbkdf2/index.d.ts' with Package ID '@types/pbkdf2/index.d.ts@3.1.0', primary: true. ========
======== Resolving type reference directive 'secp256k1', containing file '/Users/gozala/Projects/ipfs-ts-use/__inferred type names__.ts', root directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'. ========
Resolving with primary search path '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/secp256k1/package.json'.
'package.json' does not have a 'typesVersions' field.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field 'index.d.ts' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/secp256k1/index.d.ts'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/secp256k1/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/secp256k1/index.d.ts', result '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/secp256k1/index.d.ts'.
======== Type reference directive 'secp256k1' was successfully resolved to '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/secp256k1/index.d.ts' with Package ID '@types/secp256k1/index.d.ts@4.0.1', primary: true. ========
======== Resolving type reference directive 'node', containing file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bl/index.d.ts', root directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'. ========
Resolving with primary search path '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/package.json'.
'package.json' does not have a 'typesVersions' field.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field 'index.d.ts' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts', result '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts'.
======== Type reference directive 'node' was successfully resolved to '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts' with Package ID '@types/node/index.d.ts@8.10.65', primary: true. ========
======== Resolving module 'events' from '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/inspector.d.ts'. ========
Module resolution kind is not specified, using 'NodeJs'.
Loading module 'events' from 'node_modules' folder, target file type 'TypeScript'.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node_modules' does not exist, skipping all lookups in it.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/package.json'.
'package.json' does not have a 'typesVersions' field.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events.ts' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events.tsx' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events.d.ts' does not exist.
'package.json' does not have a 'typings' field.
'package.json' does not have a 'types' field.
'package.json' has 'main' field './events.js' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.js'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.js' exist - use it as a name resolution result.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.js' has an unsupported extension, so skipping it.
Loading module as file / folder, candidate module location '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.js', target file type 'TypeScript'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.js.ts' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.js.tsx' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.js.d.ts' does not exist.
File name '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.js' has a '.js' extension - stripping it.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.ts' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.tsx' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.d.ts' does not exist.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.js' does not exist, skipping all lookups in it.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/index.ts' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/index.tsx' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/index.d.ts' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/events.d.ts' does not exist.
File '/Users/gozala/Projects/node_modules/events.ts' does not exist.
File '/Users/gozala/Projects/node_modules/events.tsx' does not exist.
File '/Users/gozala/Projects/node_modules/events.d.ts' does not exist.
Directory '/Users/gozala/Projects/node_modules/@types' does not exist, skipping all lookups in it.
Directory '/Users/gozala/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
Loading module 'events' from 'node_modules' folder, target file type 'JavaScript'.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node_modules' does not exist, skipping all lookups in it.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/package.json'.
'package.json' does not have a 'typesVersions' field.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events.js' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events.jsx' does not exist.
'package.json' has 'main' field './events.js' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.js'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.js' exist - use it as a name resolution result.
Resolving real path for '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.js', result '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.js'.
======== Module name 'events' was successfully resolved to '/Users/gozala/Projects/ipfs-ts-use/node_modules/events/events.js' with Package ID 'events/events.js@3.2.0'. ========
Module 'events' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'net' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'stream' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'url' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'child_process' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'events' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'net' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'stream' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'tls' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'events' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'http' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'url' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'stream' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'readline' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'events' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'stream' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'events' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'stream' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'net' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'querystring' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'stream' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'events' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'dns' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'events' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'dns' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'stream' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'events' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'url' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'crypto' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'dns' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'net' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'stream' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'stream' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'events' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'net' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'events' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'events' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'fs' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'net' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'stream' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'tls' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'url' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'http' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
Module 'http' was resolved as locally declared ambient module in file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/base.d.ts'.
======== Resolving module 'stream' from '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bl/index.d.ts'. ========
Module resolution kind is not specified, using 'NodeJs'.
Loading module 'stream' from 'node_modules' folder, target file type 'TypeScript'.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bl/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node_modules' does not exist, skipping all lookups in it.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/stream.ts' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/stream.tsx' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/stream.d.ts' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/stream.d.ts' does not exist.
File '/Users/gozala/Projects/node_modules/stream.ts' does not exist.
File '/Users/gozala/Projects/node_modules/stream.tsx' does not exist.
File '/Users/gozala/Projects/node_modules/stream.d.ts' does not exist.
Directory '/Users/gozala/Projects/node_modules/@types' does not exist, skipping all lookups in it.
Directory '/Users/gozala/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
Loading module 'stream' from 'node_modules' folder, target file type 'JavaScript'.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bl/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node_modules' does not exist, skipping all lookups in it.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/stream.js' does not exist.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/stream.jsx' does not exist.
File '/Users/gozala/Projects/node_modules/stream.js' does not exist.
File '/Users/gozala/Projects/node_modules/stream.jsx' does not exist.
Directory '/Users/gozala/node_modules' does not exist, skipping all lookups in it.
Directory '/Users/node_modules' does not exist, skipping all lookups in it.
Directory '/node_modules' does not exist, skipping all lookups in it.
======== Module name 'stream' was not resolved. ========
======== Resolving type reference directive 'node', containing file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/bn.js/index.d.ts', root directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'. ========
Resolving with primary search path '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/package.json'.
'package.json' does not have a 'typesVersions' field.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field 'index.d.ts' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts', result '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts'.
======== Type reference directive 'node' was successfully resolved to '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts' with Package ID '@types/node/index.d.ts@8.10.65', primary: true. ========
======== Resolving type reference directive 'node', containing file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/pbkdf2/index.d.ts', root directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'. ========
Resolving with primary search path '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/package.json'.
'package.json' does not have a 'typesVersions' field.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field 'index.d.ts' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts', result '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts'.
======== Type reference directive 'node' was successfully resolved to '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts' with Package ID '@types/node/index.d.ts@8.10.65', primary: true. ========
======== Resolving type reference directive 'node', containing file '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/secp256k1/index.d.ts', root directory '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'. ========
Resolving with primary search path '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types'.
Found 'package.json' at '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/package.json'.
'package.json' does not have a 'typesVersions' field.
'package.json' does not have a 'typings' field.
'package.json' has 'types' field 'index.d.ts' that references '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts'.
File '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts', result '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts'.
======== Type reference directive 'node' was successfully resolved to '/Users/gozala/Projects/ipfs-ts-use/node_modules/@types/node/index.d.ts' with Package ID '@types/node/index.d.ts@8.10.65', primary: true. ========
node_modules/ipfs/dist/src/index.d.ts(2,35): error TS2307: Cannot find module 'ipfs-core/src' or its corresponding type declarations.

I think the problem is that once TS finally decides to look for dist/src/index.js it then goes and does path substitution once again based on typesVersions mapping dist/* and ends up looking for node_modules/ipfs-core/dist/src/dist/src/index.js instead of node_modules/ipfs-core/dist/src/index.js and fails.

I'm guessing it does not look for node_modules/ipfs-core/dist/src/dist/src/index.ts because there is no node_modules/ipfs-core/dist/src/dist directory so it skips any file lookups there.

@Gozala
Copy link
Contributor Author

Gozala commented Oct 27, 2020

I want to verify that issue still appears with typescirpt@next and if so, I'll report issue to the typescript project and see what can we do there.

@Gozala
Copy link
Contributor Author

Gozala commented Oct 27, 2020

Verified that problem still there with typescript@next, will create a simple reproducible example that I can submit to typescript.

@Gozala
Copy link
Contributor Author

Gozala commented Oct 27, 2020

Created two bug reports for typescript

I have also figured out a better solution to overcome this problem. Instead of using mapping like

"typesVersions": {
    "*": {
      "*": [
        "dist/*"
      ]
    }
  }

We could use mapping like:

"typesVersions": {
    "*": {
      "*": [
        "dist/*",
        "dist/*/index"
      ]
    }
  }

Which basically forces TS to lookup ipfs-core/src/index.

achingbrain added a commit that referenced this issue Nov 2, 2020
1. addresses #3356 in a different way based no findings in #3358. 
2. Adds ts project example that uses ipfs and tests that it type checks.
3. Adds js project example that uses ipfs and runs type checker to ensure types are picked up and inferred.
4. Changes all the `ReturnType<import(...)>`'s to `ReturnType<typeof import(...)>` as former seems to raise errors in stricter TS setup.

Co-authored-by: achingbrain <alex@achingbrain.net>
@achingbrain
Copy link
Member

require('ipfs-core') in ipfs package no longer causes invalid typedef generation so this can be closed now, right?

@Gozala Gozala closed this as completed Nov 10, 2020
SgtPooki referenced this issue in ipfs/js-kubo-rpc-client Aug 18, 2022
1. addresses #3356 in a different way based no findings in #3358. 
2. Adds ts project example that uses ipfs and tests that it type checks.
3. Adds js project example that uses ipfs and runs type checker to ensure types are picked up and inferred.
4. Changes all the `ReturnType<import(...)>`'s to `ReturnType<typeof import(...)>` as former seems to raise errors in stricter TS setup.

Co-authored-by: achingbrain <alex@achingbrain.net>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need/triage Needs initial labeling and prioritization
Projects
None yet
Development

No branches or pull requests

2 participants