maciejtreder / ng-toolkit

:star: Angular tool-box! Start your PWA in two steps! Add Serverless support for existing projects and much more
https://www.angular-universal-pwa.maciejtreder.com
MIT License
1.12k stars 156 forks source link

package.json does not exist at ...\dist\package.json #744

Open rosostolato opened 4 years ago

rosostolato commented 4 years ago

I'm submitting a...


[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request

In package


[ ] @ng-toolkit/init
[ ] @ng-toolkit/serverless
[x] @ng-toolkit/universal
[ ] @ng-toolkit/pwa
[ ] @ng-toolkit/firebug

Current behavior

I'm trying to build an angular firebase project with ssr but I get the following error: package.json does not exist at D:\Projects\Freelancer\edson-barber-shop\dist\package.json

I tried to place package.json on that folder but then I get following: Cannot find module 'D:\Projects\Freelancer\edson-barber-shop\dist\package.json'

Expected behavior

It should open up the server.

Minimal reproduction of the problem with instructions

I added @ng-toolkit/universal and ran build:ssr and then serve:ssr.

first I got a "window is not defined" then I added it to server.ts

const domino = require('domino');
const fs = require('fs');
const path = require('path');
const template = fs.readFileSync(path.join('dist/browser', 'index.html')).toString();
const win = domino.createWindow(template);
global['window'] = win;
global['document'] = win.document;
global['Event'] = {};

now I'm getting the following error:

npm run serve:ssr

> seu-edson-barber-shop@0.0.0 serve:ssr D:\Projects\Freelancer\edson-barber-shop
> node local.js

D:\Projects\Freelancer\edson-barber-shop\dist\server\main.js:190531
        throw new Error("package.json does not exist at " + package_json_path);
        ^

Error: package.json does not exist at D:\Projects\Freelancer\edson-barber-shop\dist\package.json
    at Object.PsoT.exports.find (D:\Projects\Freelancer\edson-barber-shop\dist\server\main.js:190531:15)
    at Object.wPNL (D:\Projects\Freelancer\edson-barber-shop\dist\server\main.js:358026:12)
    at __webpack_require__ (D:\Projects\Freelancer\edson-barber-shop\dist\server\main.js:20:30)
    at Object.XpdW (D:\Projects\Freelancer\edson-barber-shop\dist\server\main.js:225434:12)
    at __webpack_require__ (D:\Projects\Freelancer\edson-barber-shop\dist\server\main.js:20:30)
    at Object.g1pB (D:\Projects\Freelancer\edson-barber-shop\dist\server\main.js:264120:27)
    at __webpack_require__ (D:\Projects\Freelancer\edson-barber-shop\dist\server\main.js:20:30)
    at Object.Ou8q (D:\Projects\Freelancer\edson-barber-shop\dist\server\main.js:186719:14)
    at __webpack_require__ (D:\Projects\Freelancer\edson-barber-shop\dist\server\main.js:20:30)
    at Object.BYZf (D:\Projects\Freelancer\edson-barber-shop\dist\server\main.js:121999:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! seu-edson-barber-shop@0.0.0 serve:ssr: `node local.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the seu-edson-barber-shop@0.0.0 serve:ssr script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\eduar\AppData\Roaming\npm-cache\_logs\2019-12-26T02_32_54_467Z-debug.log

Environment


Angular version: 8.3.5


- Node version: 12.5.0 
- Platform: Windows 

Others:

This is my package.json scripts

  "scripts": {
    "ng": "ng",
    "start": "ng serve -o",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",

    "serve:ssr": "node local.js",
    "serve:prerender": "node static.js",
    "compile:server": "webpack --config webpack.server.config.js --progress --colors",
    "build:ssr": "npm run build:client-and-server-bundles && npm run compile:server",
    "build:client-and-server-bundles": "ng build --prod && ng run seu-edson-barber-shop:server:production --bundleDependencies all",
    "build:prerender": "npm run build:prod && node dist/prerender.js",
    "build:browser:prod": "ng build --prod",
    "build:browser:serverless": "ng build --prod --base-href /",
    "build:prod:deploy": "npm run build:prod && npm run deploy",
    "build:prod": "npm run build:browser:prod && npm run build:server:prod",
    "build:server:prod": "ng run seu-edson-barber-shop:server && webpack --config webpack.server.config.js --progress --colors",
    "build:serverless": "npm run build:browser:serverless && npm run build:server:serverless",
    "build:serverless:deploy": "npm run build:serverless && npm run deploy",
    "build:server:serverless": "ng run seu-edson-barber-shop:server && webpack --config webpack.server.config.js --progress --colors",
    "deploy": "cp-cli dist/ functions/dist/ && cd functions && npm install && firebase deploy"
  },
KingDarBoja commented 4 years ago

Hello @rosostolato

Can you provide a repository to look at it?

rosostolato commented 4 years ago

Sure... I created a new repository, added firebase configs, created a home module being lazy loaded and the error persists. Check here the repository.