sindresorhus / p-limit

Run multiple promise-returning & async functions with limited concurrency
MIT License
1.84k stars 99 forks source link

Why are there no parentheses after the catch statement #42

Closed nieyuyao closed 3 years ago

nieyuyao commented 3 years ago

I don’t know if this is a new way of writing, but there will be an error without parentheses 😱

ShachMaT commented 3 years ago

I don’t know if this is a new way of writing, but there will be an error without parentheses

Just to be specific, you mean this:

const run = async (fn, resolve, ...args) => {
    activeCount++;

    // TODO: Get rid of 'pTry'. It's not needed anymore.
    const result = pTry(fn, ...args);

    resolve(result);

    try {
        await result;
    } catch {}
        next();
};

Should be that:

const run = async (fn, resolve, ...args) => {
    activeCount++;

    // TODO: Get rid of 'pTry'. It's not needed anymore.
    const result = pTry(fn, ...args);

    resolve(result);

    try {
        await result;
    } catch (e) {}
        next();
};

Otherwise it cause this:

/node_modules/copy-webpack-plugin/node_modules/p-limit/index.js:30
        } catch {}
                ^

SyntaxError: Unexpected token {
    at NativeCompileCache._moduleCompile (/node_modules/v8-compile-cache/v8-compile-cache.js:240:18)
    at Module._compile (/node_modules/v8-compile-cache/v8-compile-cache.js:186:36)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/node_modules/copy-webpack-plugin/dist/index.js:10:38)
    at Module._compile (/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/node_modules/copy-webpack-plugin/dist/cjs.js:3:16)
    at Module._compile (/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/webpack/webpack.config.prod.js:7:27)
    at Module._compile (/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! paytel-frontend@1.0.0 build:production: `cross-env NODE_ENV=production webpack --config webpack/webpack.config.prod.js --colors`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the paytel-frontend@1.0.0 build:production script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
nieyuyao commented 3 years ago

I don’t know if this is a new way of writing, but there will be an error without parentheses

Just to be specific, you mean this:

const run = async (fn, resolve, ...args) => {
    activeCount++;

    // TODO: Get rid of 'pTry'. It's not needed anymore.
    const result = pTry(fn, ...args);

    resolve(result);

    try {
        await result;
    } catch {}
        next();
};

Should be that:

const run = async (fn, resolve, ...args) => {
    activeCount++;

    // TODO: Get rid of 'pTry'. It's not needed anymore.
    const result = pTry(fn, ...args);

    resolve(result);

    try {
        await result;
    } catch (e) {}
        next();
};

Otherwise it cause this:

/node_modules/copy-webpack-plugin/node_modules/p-limit/index.js:30
      } catch {}
              ^

SyntaxError: Unexpected token {
    at NativeCompileCache._moduleCompile (/node_modules/v8-compile-cache/v8-compile-cache.js:240:18)
    at Module._compile (/node_modules/v8-compile-cache/v8-compile-cache.js:186:36)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/node_modules/copy-webpack-plugin/dist/index.js:10:38)
    at Module._compile (/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/node_modules/copy-webpack-plugin/dist/cjs.js:3:16)
    at Module._compile (/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.<anonymous> (/webpack/webpack.config.prod.js:7:27)
    at Module._compile (/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! paytel-frontend@1.0.0 build:production: `cross-env NODE_ENV=production webpack --config webpack/webpack.config.prod.js --colors`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the paytel-frontend@1.0.0 build:production script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Yes, the problem I encountered is this error !

ShachMaT commented 3 years ago

Okay so while i encountered this error running Node v8.17 after installing v12 everything is fine.

Try updating Node or using NVM to use different versions of Node.

Edit: In code view you can see comment that states that package require Node v10 or newer. I think this should be clearly stated in readme. Also, also, i wonder why when running npm install there is no warning or error when running Node older than v10

sindresorhus commented 3 years ago

Duplicate of #33

sindresorhus commented 3 years ago

Also, also, i wonder why when running npm install there is no warning or error when running Node older than v10

That would be something to bring up on https://github.com/npm/cli/issues

sindresorhus commented 3 years ago

In code view you can see comment that states that package require Node v10 or newer. I think this should be clearly stated in readme.

It's defined in package.json in pretty much all npm packages. That's just how it works. I don't intend to duplicate that information in multiple places.