tschaub / es-main

Test if an ES module is run directly (require.main replacement)

Home Page:https://www.npmjs.com/package/es-main

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

esMain(import.meta) pops an error

harleyguru opened this issue · comments

Hey,

I am getting the following error with esMain(import.meta) line:

iMac:api ninjablade$ sls deploy
Serverless: Bundling with Webpack...

ERROR in /Volumes/Work/Work/Workspace/+Purpose/Backend/services/api/user.js 105:17
Module parse failed: Unexpected token (105:17)
File was processed with these loaders:
 * ../../babel-loader/lib/index.js
 * ../node_modules/eslint-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
| });
| 
> if (esMain(import.meta)) {
|   get(mock);
| }

ERROR in /Volumes/Work/Work/Workspace/+Purpose/Backend/services/api/user.js 105:17
Module parse failed: Unexpected token (105:17)
File was processed with these loaders:
 * ../../babel-loader/lib/index.js
 * ../node_modules/eslint-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
| });
| 
> if (esMain(import.meta)) {
|   get(mock);
| }
 
 Error ---------------------------------------------------
 
  Error: Webpack compilation error, see stats above
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/serverless-webpack/lib/compile.js:32:15
      at arrayEach (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/lodash/lodash.js:530:11)
      at Function.forEach (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/lodash/lodash.js:9410:14)
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/serverless-webpack/lib/compile.js:29:7
      at tryCatcher (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/bluebird/js/release/promise.js:729:18)
      at Promise._fulfill (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/bluebird/js/release/promise.js:673:18)
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/bluebird/js/release/nodeback.js:42:21
      at finalCallback (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compiler.js:257:39)
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compiler.js:273:13
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/Hook.js:154:20)
      at onCompiled (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compiler.js:271:21)
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compiler.js:681:15
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/Hook.js:154:20)
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compiler.js:678:31
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/Hook.js:154:20)
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compilation.js:1423:35
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/Hook.js:154:20)
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compilation.js:1414:32
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/Hook.js:154:20)
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compilation.js:1409:36
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/Hook.js:154:20)
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compilation.js:1405:32
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at AsyncSeriesHook.lazyCompileHook (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/Hook.js:154:20)
      at Compilation.seal (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compilation.js:1342:27)
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compiler.js:675:18
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compilation.js:1261:4
      at AsyncSeriesHook.eval [as callAsync] (eval at create (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
      at AsyncSeriesHook.lazyCompileHook (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/Hook.js:154:20)
      at Compilation.finish (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compilation.js:1253:28)
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compiler.js:672:17
      at eval (eval at create (/Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:11:1)
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compilation.js:1185:12
      at /Volumes/Work/Work/Workspace/+Purpose/Backend/node_modules/webpack/lib/Compilation.js:1097:9
      at processTicksAndRejections (internal/process/task_queues.js:75:11)
 
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              14.16.1
     Framework Version:         2.52.1
     Plugin Version:            5.4.3
     SDK Version:               4.2.3
     Components Version:        3.14.2

The strange thing is that this is only happening with webpack bundling.. when I run it locally, it doesn't have any error.

@harleyguru - Thanks for the report. I'm going to close this as it looks like a problem with the Webpack/Babel configuration related to parsing ES Modules. It doesn't look like a problem specific to the es-main package. But please reopen if you think this has something to do with this package specifically.