You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And run the deploy script against any valid project. The index file is intentionally empty since the error is thrown before that matters.
[REQUIRED] Expected behavior
The main index.js file is successfully imported as an es6 module.
[REQUIRED] Actual behavior
This error is thrown when attempting to deploy:
Error: Error occurred while parsing your function triggers.
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/joelt/project/firebase-tools-issue/index.js
require() of ES modules is not supported.
require() of /home/joelt/project/firebase-tools-issue/index.js from /home/joelt/project/firebase-tools-issue/node_modules/firebase-tools/lib/triggerParser.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/joelt/project/firebase-tools-issue/package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at /home/joelt/project/firebase-tools-issue/node_modules/firebase-tools/lib/triggerParser.js:15:15
at Object.<anonymous> (/home/joelt/project/firebase-tools-issue/node_modules/firebase-tools/lib/triggerParser.js:53:3)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
It looks like the error originates from this line:
@joelclimbsthings thanks for the clear reproduction! I was able to reproduce your issue and I noticed that it only happens when "type": "module" is declared in package.json.
@mbleigh@bkendall@abeisgoat any idea what we can do about this? I tried to experiment with reading the type field of the package.json and then using import() instead of require() but because our tsconfig.json specifies module: "commonjs" the import call gets compiled down to a require call by TypeScript.
Is the answer just that we don't support ES6 modules?
I was able to reproduce your issue and I noticed that it only happens when "type": "module" is declared in package.json.
Thanks for the prompt response, @samtstern ! Correct, the main reason I was giving v14 a spin with my functions was the support of es6 modules, and those are only supported within Node.js when type: module is declared. My main reason for giving v14 a spin was these modules, so that's basically my question as well; are they meant to be supported?
[REQUIRED] Environment info
firebase-tools: 9.10.0
Platform: Ubuntu
[REQUIRED] Test case
Provided a small PoC repo here: https://github.com/joelclimbsthings/firebase-tools-es6-modules-issue
Basically, it's just a basic project with the "engine" set to
14
and trying to deploy.[REQUIRED] Steps to reproduce
Check out this repo: https://github.com/joelclimbsthings/firebase-tools-es6-modules-issue
And run the
deploy
script against any valid project. The index file is intentionally empty since the error is thrown before that matters.[REQUIRED] Expected behavior
The main
index.js
file is successfully imported as an es6 module.[REQUIRED] Actual behavior
This error is thrown when attempting to deploy:
It looks like the error originates from this line:
firebase-tools/src/triggerParser.js
Line 21 in 04ca608
And changing the
require()
to animport()
would seem to remedy the issue (or at least the error).Is there any kind of workaround for this? I'm just experiementing with using the beta Node v14 engine to support es6 module syntax.
The text was updated successfully, but these errors were encountered: