package-build-stats icon indicating copy to clipboard operation
package-build-stats copied to clipboard

when i want to find out size of package 'zx', it throw a build error: 'Cannot use keyword 'await' outside an async function'

Open cy-98 opened this issue 3 years ago • 1 comments

when i want to find out size of package 'zx', it throw a build error: 'Cannot use keyword 'await' outside an async function'

it seems, zx used new feature of node. Is package-build-stats only support to build web package?

How can i get size of node package which used node feature without webpack loader?

cy-98 avatar Jul 08 '21 03:07 cy-98

Without seeing a code example, my best guess is that you're doing something like this:

const { getPackageStats } = require('package-build-stats')

const result = await getPackageStats('some-package');

console.log(result);

Generally, you can't call await outside of an async function, meaning: you need to wrap whatever is calling await in an async function, like this:

// index.js
const { getPackageStats } = require('package-build-stats')

async function getStats() {
    const results = await getPackageStats('faker')

    console.log(results);
}

getStats();

Does this get you any further? Or were you trying something else? Give us an example so we can point you in the right direction.

parties avatar Sep 04 '23 23:09 parties