bitcoinjs / bitcoinjs-lib

A javascript Bitcoin library for node.js and browsers.
MIT License
5.69k stars 2.11k forks source link

Question: Error: Cannot find module 'bitcoinjs-lib/types/bufferutils' #1615

Closed ishaq closed 4 years ago

ishaq commented 4 years ago

Pardon the newbie question. My code, typescript, is:

import { BufferWriter } from 'bitcoinjs-lib/types/bufferutils';

// ... now use BufferWriter

this compiles fine but when I run it (using node). it throws:

Error: Cannot find module 'bitcoinjs-lib/types/bufferutils'

Is BufferWriter not supposed to be used outside of bitcoinjs-lib? or is something wrong in my code? Thank you.

junderw commented 4 years ago

We separate types from src, you need to set up aliases in your tsconfig.json iirc. Your question should be directed to a TypeScript forum.

That said, you should not be accessing internal items as they can break without warning. Be careful.

junderw commented 4 years ago

path mapping will help

https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping

Set one key of the paths object to

bitcoinjs-lib/src/bufferutils

and the value to an array with one string

bitcoinjs-lib/types/bufferutils