analogjs / analog

The fullstack meta-framework for Angular. Powered by Vite and Nitro
https://analogjs.org
MIT License
2.5k stars 236 forks source link

Issue when building @angular/fire in Nx #1108

Closed dalenguyen closed 2 months ago

dalenguyen commented 3 months ago

Please provide the environment you discovered this bug in.

It happens at build time. You can try at by cloning my repo and run the build script. It works fine when serve and deploy using node, but this error just bugs me.

https://github.com/dalenguyen/pdfun

Analog: 1.3.1 NX: 19 Angular: 18

Which area/package is the issue in?

vite-plugin-nitro

Description

Found this error when running the build script. Here is my package.json content

{
  "name": "@pdfun/source",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
  },
  "private": true,
  "dependencies": {
    "@analogjs/content": "1.3.1",
    "@analogjs/router": "1.3.1",
    "@angular/animations": "18.0.0",
    "@angular/common": "18.0.0",
    "@angular/compiler": "18.0.0",
    "@angular/core": "18.0.0",
    "@angular/fire": "^17.1.0",
    "@angular/forms": "18.0.0",
    "@angular/platform-browser": "18.0.0",
    "@angular/platform-browser-dynamic": "18.0.0",
    "@angular/platform-server": "18.0.0",
    "@angular/router": "18.0.0",
    "@google-cloud/firestore": "^7.7.0",
    "@google-cloud/storage": "^7.11.1",
    "firebase-admin": "^12.1.0",
    "firebase-functions": "^5.0.1",
    "front-matter": "^4.0.2",
    "marked": "^5.0.2",
    "marked-gfm-heading-id": "^3.1.0",
    "marked-highlight": "^2.0.1",
    "mermaid": "^10.2.4",
    "nanoid": "^5.0.7",
    "prismjs": "^1.29.0",
    "rxjs": "~7.5.6",
    "shelljs": "^0.8.5",
    "tslib": "^2.4.0",
    "zone.js": "~0.14.0"
  },
  "devDependencies": {
    "@analogjs/platform": "1.3.1",
    "@analogjs/vite-plugin-angular": "1.3.1",
    "@angular-devkit/build-angular": "18.0.1",
    "@angular-devkit/core": "18.0.1",
    "@angular-devkit/schematics": "18.0.1",
    "@angular-eslint/eslint-plugin": "~17.3.0",
    "@angular-eslint/eslint-plugin-template": "~17.3.0",
    "@angular-eslint/template-parser": "~17.3.0",
    "@angular/compiler-cli": "18.0.0",
    "@nx/angular": "19.1.0",
    "@nx/devkit": "19.1.0",
    "@nx/esbuild": "19.1.0",
    "@nx/eslint": "19.1.0",
    "@nx/eslint-plugin": "19.1.0",
    "@nx/eslint-plugin-nx": "^16.0.0-beta.4",
    "@nx/jest": "19.1.0",
    "@nx/js": "19.1.0",
    "@nx/node": "19.1.0",
    "@nx/vite": "19.1.0",
    "@nx/workspace": "19.1.0",
    "@schematics/angular": "18.0.1",
    "@swc-node/register": "1.8.0",
    "@swc/core": "~1.3.85",
    "@swc/helpers": "~0.5.2",
    "@swc/jest": "0.2.20",
    "@types/jest": "^29.4.0",
    "@types/node": "18.16.9",
    "@types/shelljs": "^0.8.15",
    "@typescript-eslint/eslint-plugin": "^7.3.0",
    "@typescript-eslint/parser": "^7.3.0",
    "autoprefixer": "^10.4.0",
    "esbuild": "^0.19.2",
    "eslint": "~8.57.0",
    "eslint-config-prettier": "^9.0.0",
    "jest": "^29.4.1",
    "jest-environment-jsdom": "^29.4.1",
    "jest-environment-node": "^29.4.1",
    "jest-preset-angular": "14.1.0",
    "jsdom": "^22.1.0",
    "nx": "19.1.0",
    "postcss": "^8.4.5",
    "prettier": "^2.6.2",
    "tailwindcss": "^3.0.2",
    "ts-jest": "^29.1.0",
    "ts-node": "10.9.1",
    "typescript": "5.4.5",
    "vite": "^5.0.0",
    "vite-tsconfig-paths": "^4.2.0",
    "vitest": "^1.3.1"
  },
  "optionalDependencies": {
    "@nx/nx-darwin-arm64": "18.0.0",
    "@nx/nx-darwin-x64": "18.0.0",
    "@nx/nx-linux-x64-gnu": "18.0.0",
    "@nx/nx-win32-x64-msvc": "18.0.0"
  }
}

Please provide the exception or error you saw

This is the error when running the build script:

Prerendering static pages...
Building Server...
Error: Cannot find module firebase imported from file:///Users/dalenguyen/projects/github/pdfun/node_modules, file:///Users/dalenguyen/projects/github/pdfun/pdf/node_modules, file:///Users/dalenguyen/projects/github/pdfun/node_modules/nitropack/node_modules, file:///Users/dalenguyen/projects/github/pdfun/, file:///Users/dalenguyen/projects/github/pdfun/node_modules/_index.js, file:///Users/dalenguyen/projects/github/pdfun/node_modules, file:///Users/dalenguyen/projects/github/pdfun/pdf/, file:///Users/dalenguyen/projects/github/pdfun/pdf/node_modules/_index.js, file:///Users/dalenguyen/projects/github/pdfun/pdf/node_modules, file:///Users/dalenguyen/projects/github/pdfun/node_modules/nitropack/, file:///Users/dalenguyen/projects/github/pdfun/node_modules/nitropack/node_modules/_index.js, file:///Users/dalenguyen/projects/github/pdfun/node_modules/nitropack/node_modules
    at _resolve (file:///Users/dalenguyen/projects/github/pdfun/node_modules/mlly/dist/index.mjs:2102:19)
    at resolveSync (file:///Users/dalenguyen/projects/github/pdfun/node_modules/mlly/dist/index.mjs:2111:10)
    at resolvePathSync (file:///Users/dalenguyen/projects/github/pdfun/node_modules/mlly/dist/index.mjs:2121:24)
    at resolvePath (file:///Users/dalenguyen/projects/github/pdfun/node_modules/mlly/dist/index.mjs:2125:28)
    at _resolve (file:///Users/dalenguyen/projects/github/pdfun/node_modules/nitropack/dist/nitro.mjs:424:22)
    at Object.resolveId (file:///Users/dalenguyen/projects/github/pdfun/node_modules/nitropack/dist/nitro.mjs:488:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Error: Cannot find module firebase/firestore/dist/index.mjs imported from file:///Users/dalenguyen/projects/github/pdfun/node_modules, file:///Users/dalenguyen/projects/github/pdfun/pdf/node_modules, file:///Users/dalenguyen/projects/github/pdfun/node_modules/nitropack/node_modules, file:///Users/dalenguyen/projects/github/pdfun/, file:///Users/dalenguyen/projects/github/pdfun/node_modules/_index.js, file:///Users/dalenguyen/projects/github/pdfun/node_modules, file:///Users/dalenguyen/projects/github/pdfun/pdf/, file:///Users/dalenguyen/projects/github/pdfun/pdf/node_modules/_index.js, file:///Users/dalenguyen/projects/github/pdfun/pdf/node_modules, file:///Users/dalenguyen/projects/github/pdfun/node_modules/nitropack/, file:///Users/dalenguyen/projects/github/pdfun/node_modules/nitropack/node_modules/_index.js, file:///Users/dalenguyen/projects/github/pdfun/node_modules/nitropack/node_modules
    at _resolve (file:///Users/dalenguyen/projects/github/pdfun/node_modules/mlly/dist/index.mjs:2102:19)
    at resolveSync (file:///Users/dalenguyen/projects/github/pdfun/node_modules/mlly/dist/index.mjs:2111:10)
    at resolvePathSync (file:///Users/dalenguyen/projects/github/pdfun/node_modules/mlly/dist/index.mjs:2121:24)
    at resolvePath (file:///Users/dalenguyen/projects/github/pdfun/node_modules/mlly/dist/index.mjs:2125:28)
    at _resolve (file:///Users/dalenguyen/projects/github/pdfun/node_modules/nitropack/dist/nitro.mjs:424:22)
    at Object.resolveId (file:///Users/dalenguyen/projects/github/pdfun/node_modules/nitropack/dist/nitro.mjs:493:57) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Other information

No response

I would be willing to submit a PR to fix this issue

WolfSoko commented 3 months ago

Similar issue here. Also a windows machine. When I try to deploy it to firebase. It leads to similar path errors for the firebase functions. Currently I'm not sure how to solve them.

dalenguyen commented 3 months ago

Similar issue here. Also a windows machine. When I try to deploy it to firebase. It leads to similar path errors for the firebase functions.

Currently I'm not sure how to solve them.

I'm working with ssr: false flag at the moment to overcome this. If the app requires authentication, it's hard to configure it for SSR.

brandonroberts commented 3 months ago

I don't have a Windows machine so any assistance would be helpful here. Is firebase included as a direct dependency?

And does this happen outside of Windows environments?

brandonroberts commented 3 months ago

@dalenguyen I sent you a PR to fix your build issue. I could reproduce the issue on my machine also even though its not windows

brandonroberts commented 3 months ago

@WolfSoko you may need the same config for SSR

https://github.com/brandonroberts/dalenguyen-pdfun/blob/92af155390330e81c7b567202240cd33e4442e26/pdf/vite.config.ts#L25

dalenguyen commented 3 months ago

@dalenguyen I sent you a PR to fix your build issue. I could reproduce the issue on my machine also even though its not windows

Thanks, @brandonroberts. I think you sent a PR to your own repo :D

I'm using Mac though.

brandonroberts commented 3 months ago

🤦

Ok cool