简体   繁体   中英

_util.default.promisify is not a function using Node 9.5

Node version:

node -v
v9.5.0

Code

import util from 'util'
import fingerprint from 'fingerprint2'
const Fingerprint = util.promisify(fingerprint.get)

The error I'm getting in the browser is:

Uncaught TypeError: _util.default.promisify is not a function

According to the docs it's supported. Any idea what is happening here?

I have also tried:

import { promisify } from 'util'

And

import util from 'util'
const { promisify } from util

... Same error.

Ok I managed to solve it. As this is a browser application it should have installed es6-promisify . Node's promisify will not work for obvious reasons. I should have realised that.

import something from 'package';

is a shortand for

var something = require('package').default;

Use

import { promisify } from 'util';

instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM