Skip to content

Pre-render 'Template execution failed' when importing Firebase Auth v9 #1633

Open
@rejhgadellaa

Description

@rejhgadellaa

What is the current behaviour?

I'm working on a project that uses Firebase v9 and I'm getting an error when I run npm run build:

× ERROR Template execution failed: SyntaxError: Function statements require a function name

The error is thrown in prerender.js @ line 18:

let m = require(entry),

When I check the ./ssr-build/ssr-bundle.js it's trying to require, I can see the syntax error.

To be honest, I'm not sure if this is the right project to file this issue. It looks like it's Terser messing up the ssr-bundle.js or maybe it's Firebase's auth module that has some syntax that causes Terser to mess up, etc, but I guess I have to start filing the issue somewhere :)

Steps to Reproduce

Steps to reproduce the behavior:

  1. Create a new project: npx preact-cli create default my-project
  2. Install firebase v9: npm i firebase (note: I have the latest 9.6.1 version)
  3. Import { getAuth } from 'firebase/auth' in src/routes/Home/
  4. Run npm run build

I've included a zip of a project that I created using these steps.

  1. Download the zip (attached)
  2. Run npm install && npm run build

firebase-auth-ssr-minimize-error--zip.zip

What is the expected behaviour?

ssr-bundle.js should not contain a javascript syntax error causing the build to fail.

Please mention any other relevant information

  • The project builds fine with --no-prerender
  • The project builds fine when I disable minification in preact.config.js: config.optimization.minimize = false;

Both the 'modular' v9 as the 'compat' version of Firebase Auth causes the error:

// This:
import { getAuth } from 'firebase/auth';

// Same as:
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';

npx preact-cli info:

Environment Info:
  System:
    OS: Windows 10 10.0.19044
    CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
  Binaries:
    Node: 14.16.1 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.15 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (96.0.1054.62)
  npmPackages:
    preact: ^10.3.2 => 10.6.4
    preact-cli: ^3.0.0 => 3.3.3
    preact-render-to-string: ^5.1.4 => 5.1.19
    preact-router: ^3.2.1 => 3.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions