This repository was archived by the owner on Nov 22, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 22, 2024. It is now read-only.
npm run serve:ssr : package.json does not exist #1207
Copy link
Copy link
Closed
Labels
Description
Bug Report
What is the expected behavior?
npm run build:ssr is building without errors. npm run serve:ssr is not running as expected
What is the current behavior?
npm run serve:ssr fails with the following errors
> x-y-z@0.0.0 serve:ssr /Users/NRMac/Projects/newSMT/xyz
> node dist/server
/Users/NRMac/Projects/newSMT/xyz/dist/server/main.js:173019
throw new Error("package.json does not exist at " + package_json_path);
^
Error: package.json does not exist at /Users/NRMac/Projects/newSMT/xyz/dist/package.json
at Object.PsoT.exports.find (/Users/NRMac/Projects/newSMT/xyz/dist/server/main.js:173019:15)
at Object.wPNL (/Users/NRMac/Projects/newSMT/xyz/dist/server/main.js:308568:12)
at __webpack_require__ (/Users/NRMac/Projects/newSMT/xyz/dist/server/main.js:20:30)
at Object.XpdW (/Users/NRMac/Projects/newSMT/xyz/dist/server/main.js:196998:12)
at __webpack_require__ (/Users/NRMac/Projects/newSMT/xyz/dist/server/main.js:20:30)
at Object.g1pB (/Users/NRMac/Projects/newSMT/xyz/dist/server/main.js:229730:27)
at __webpack_require__ (/Users/NRMac/Projects/newSMT/xyz/dist/server/main.js:20:30)
at Object.Ou8q (/Users/NRMac/Projects/newSMT/xyz/dist/server/main.js:170377:14)
at __webpack_require__ (/Users/NRMac/Projects/newSMT/xyz/dist/server/main.js:20:30)
at Object.BYZf (/Users/NRMac/Projects/newSMT/xyz/dist/server/main.js:99702:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! set-my-test@0.0.0 serve:ssr: `node dist/server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the set-my-test@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! /Users/NRMac/.npm/_logs/2019-07-22T07_43_50_405Z-debug.log
What modules are related to this issue?
- [ ] aspnetcore-engine
- [ ] common
- [ ] express-engine
- [ ] hapi-engine
- [ ] module-map-ngfactory-loader
Minimal reproduction with instructions:
What is the use-case or motivation for changing an existing behavior?
Environment:
@nguniversal versions
- express-engine:
- module-map-ngfactory-loader:
Output from: ng --version.
Angular CLI: 8.1.2
Node: 10.16.0
OS: darwin x64
Angular: 8.1.2
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router
Package Version
--------------------------------------------------------------------
@angular-devkit/architect 0.801.2
@angular-devkit/build-angular 0.801.2
@angular-devkit/build-optimizer 0.801.2
@angular-devkit/build-webpack 0.801.2
@angular-devkit/core 8.1.2
@angular-devkit/schematics 8.1.2
@angular/fire 5.2.1
@ngtools/webpack 8.1.2
@nguniversal/express-engine 8.1.1
@nguniversal/module-map-ngfactory-loader 8.1.1
@schematics/angular 8.1.2
@schematics/update 0.801.2
rxjs 6.5.2
typescript 3.4.5
webpack 4.35.2
Is there anything else we should know?
Working on Angular 8.1 with Firestore
Tried modifying webpack.server.config.js, package.json and server.ts based on the issue here https://stackoverflow.com/questions/57030914/firebase-firestore-not-working-with-angular-universal-package-json-does-not-exi
webpack.server.config.js
// Work around for https://github.com/angular/angular-cli/issues/7200
const path = require("path");
const webpack = require("webpack");
const APP_NAME = "xyz"; // CHANGE ME
module.exports = {
mode: "development",
entry: {
// This is our Express server for Dynamic universal
server: "./server.ts"
},
resolve: { extensions: [".js", ".ts"] },
externals: {
"./dist/server/main": 'require("./server/main")'
/* Firebase has some troubles being webpacked when in
in the Node environment, let's skip it.
Note: you may need to exclude other dependencies depending
on your project. */
// /^firebase/
},
target: "node",
optimization: {
minimize: false
},
output: {
// Puts the output at the root of the dist folder
path: path.join(__dirname, `dist/${APP_NAME}`),
library: "app",
libraryTarget: "umd",
filename: "[name].js"
},
module: {
noParse: /polyfills-.*\.js/,
rules: [
{ test: /\.ts$/, loader: "ts-loader" },
{
// Mark files inside `@angular/core` as using SystemJS style dynamic imports.
// Removing this will cause deprecation warnings to appear.
test: /(\\|\/)@angular(\\|\/)core(\\|\/).+\.js$/,
parser: { system: true }
}
]
},
plugins: [
new webpack.ContextReplacementPlugin(
// fixes WARNING Critical dependency: the request of a dependency is an expression
/(.+)?angular(\\|\/)core(.+)?/,
path.join(__dirname, "src"), // location of your src
{} // a map of your routes
),
new webpack.ContextReplacementPlugin(
// fixes WARNING Critical dependency: the request of a dependency is an expression
/(.+)?express(\\|\/)(.+)?/,
path.join(__dirname, "src"),
{}
)
]
};
server.ts
/**
* *** NOTE ON IMPORTING FROM ANGULAR AND NGUNIVERSAL IN THIS FILE ***
*
* If your application uses third-party dependencies, you'll need to
* either use Webpack or the Angular CLI's `bundleDependencies` feature
* in order to adequately package them for use on the server without a
* node_modules directory.
*
* However, due to the nature of the CLI's `bundleDependencies`, importing
* Angular in this file will create a different instance of Angular than
* the version in the compiled application code. This leads to unavoidable
* conflicts. Therefore, please do not explicitly import from @angular or
* @nguniversal in this file. You can export any needed resources
* from your application's main.server.ts file, as seen below with the
* import for `ngExpressEngine`.
*/
import "zone.js/dist/zone-node";
import "reflect-metadata";
import { enableProdMode } from "@angular/core";
import * as express from "express";
import { join } from "path";
import { readFileSync } from "fs";
// Polyfills required for Firebase
(global as any).WebSocket = require("ws");
(global as any).XMLHttpRequest = require("xhr2");
import { renderModuleFactory } from "@angular/platform-server";
import { REQUEST, RESPONSE } from "@nguniversal/express-engine/tokens";
import { ValueProvider } from "@angular/core";
// Express server
enableProdMode();
const app = express();
const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), "dist");
const APP_NAME = "xyz"; // CHANGE ME
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const {
AppServerModuleNgFactory,
LAZY_MODULE_MAP,
ngExpressEngine,
provideModuleMap
} = require(`./dist/server/main`);
// index.html template
const template = readFileSync(
join(DIST_FOLDER, "browser", "index.html")
).toString();
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
// app.engine('html', ngExpressEngine({
// bootstrap: AppServerModuleNgFactory,
// providers: [
// provideModuleMap(LAZY_MODULE_MAP)
// ]
// }));
app.engine("html", (_, options, callback) =>
ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP),
{
provide: REQUEST,
useValue: options.req
},
{
provide: RESPONSE,
useValue: options.req.res
}
]
})(_, options, callback)
);
app.set("view engine", "html");
app.set("views", join(DIST_FOLDER, "browser"));
// Example Express Rest API endpoints
// app.get('/api/**', (req, res) => { });
// Serve static files from /browser
app.get(
"*.*",
express.static(DIST_FOLDER, {
maxAge: "1y"
})
);
// All regular routes use the Universal engine
// app.get("*", (req, res) => {
// res.render("index", { req });
// });
// Serve static files from /browser
app.get(
"*.*",
express.static(join(DIST_FOLDER, "browser"), {
maxAge: "1y"
})
);
// All regular routes use the Universal engine
app.get("*", (req, res) => {
res.render(join(DIST_FOLDER, "browser", "index.html"), { req });
});
// Start up the Node server
app.listen(PORT, () => {
console.log(`Node Express server listening on http://localhost:${PORT}`);
});
Package.json
{
"name": "x-of-y",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"compile:server": "webpack --config webpack.server.config.js --progress --colors",
"serve:ssr": "node dist/server",
"build:ssr": "npm run build:client-and-server-bundles && npm run compile:server",
"build:client-and-server-bundles": "ng build --prod && ng run xyz:server:production --bundleDependencies all"
},
"private": true,
"dependencies": {
"@angular/animations": "~8.1.2",
"@angular/common": "~8.1.2",
"@angular/compiler": "~8.1.2",
"@angular/core": "~8.1.2",
"@angular/forms": "~8.1.2",
"@angular/platform-browser": "~8.1.2",
"@angular/platform-browser-dynamic": "~8.1.2",
"@angular/platform-server": "~8.1.2",
"@angular/router": "~8.1.2",
"@nguniversal/express-engine": "^8.1.1",
"@nguniversal/module-map-ngfactory-loader": "8.1.1",
"animate.css": "^3.7.2",
"core-js": "^2.5.4",
"express": "^4.15.2",
"rxjs": "~6.5.2",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.801.2",
"@angular/cli": "~8.1.2",
"@angular/compiler-cli": "~8.1.2",
"@angular/fire": "^5.2.1",
"@angular/language-service": "~8.1.2",
"@fortawesome/fontawesome-free": "^5.9.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"chart.js": "^2.8.0",
"codelyzer": "^5.0.1",
"easy-pie-chart": "^2.1.7",
"firebase": "^6.3.0",
"hammerjs": "^2.0.8",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"ngx-quill": "^7.1.0",
"protractor": "~5.4.0",
"quill": "^1.3.6",
"quill-emoji": "^0.1.7",
"screenfull": "^4.2.0",
"tinify": "^1.6.0-beta.2",
"ts-loader": "^5.2.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.4.5",
"webpack-cli": "^3.1.0"
}
}
Reacted by Stephane SEGNING LAMBOU, Bdair, nseverini, Dennis Alund, Roberto Simonetti, darshanDevrai, Li Ihor, Aliaksandr Zhukau, Amr Ibrahim, Oscar FOUOMA and 6 more
Activity
bdairy commentedon Jul 25, 2019
Did u get to solve this issue??
anuragd7 commentedon Jul 26, 2019
Not yet, hoping for a response from the community.
kpsrinivas commentedon Jul 27, 2019
The problem is "build:client-and-server-bundles": "ng build --prod && ng run your-project:server:production --bundleDependencies all" in package.json . When you change it to ng run your-project:server:production --bundleDependencies none it works. But if you try to package it, the externals are getting messed up.
vikerman commentedon Jul 30, 2019
Thanks @kpsrinivas . We don't currently allow configuring what libraries should be made external. Can you tell me which library you are trying to use that is causing this issue?
kpsrinivas commentedon Jul 30, 2019
Not the library. When I try to package my server as umd and import it for firebase functions.
kpsrinivas commentedon Jul 30, 2019
This step https://github.com/angular/angularfire2/blob/master/docs/universal/cloud-functions.md fails
I know its not universal issue. But build fails.
vikerman commentedon Jul 30, 2019
We have multiple people using angular fire who seem to have problem with --bundleDependencies all. The current workaround is to just remove/set --bundleDependencies none.
We are going to follow up with angularfire folks to fix this properly
darshanDevrai commentedon Aug 26, 2019
Has anyone solved this issue yet?
@kpsrinivas @vikerman @bdairy @anuragd7
Mph1399 commentedon Sep 11, 2019
BeSpunky commentedon Sep 11, 2019
This sounds like a work around rather than a solution.
Isn't
--bundleDependencies allthere for a reason?zeeshanshanif commentedon Sep 16, 2019
i have tried "--bundleDependencies none" but still getting error
vikerman commentedon Sep 16, 2019
@zeeshanshanif - Anyway you can create a repro github repo?
@BeSpunky - Bundling does help in fast cold start times and so it is definitely the way we are heading towards. But there are some packages that don't bundle well - And we want to provide an escape hatch for those cases. In some cases it might just be temporary as we figure out how to bundle a particular dependency better.
unrealbato commentedon Nov 10, 2019
any Updates? "--bundleDependencies none" work to avoid "package.json" issue but i faced another issue as i guess that the SSR doesn't wait for observable to fetch data from Firestore! i don't know how to properly fix this.
all i want is to fetch user object from Firestore & update meta tags for Facebook Crawls share debugger!!!!
any Help Would be appreciated. Thanks
BeSpunky commentedon Nov 10, 2019
If you solved the bundling problem, your question is not related to this thread.
However, if I understand your problem correctly, this might help you:
https://stackoverflow.com/a/50065783/4371525
19 remaining items
ritikrishu commentedon Jan 17, 2020
this does resolve the build error. but when the function executes, it gives a runtime error
angular version 9^
alan-agius4 commentedon Jan 17, 2020
@ranjitpatra you also need to exclude
grpcfrom bundling.See: #1207 (comment)
naingaungphyo commentedon Jan 26, 2020
@kuncevic yeah, I got the same error for using angularfire. current workaround is by setting grpc as externalDependencies as @alan-agius4 said.
codemysoul commentedon Feb 17, 2020
If you can, you could create a separate module for Browser, and import AngularFire modules there.
For example, create a app.browser.module.ts - and add all your AngularFire imports there.
Then just point your main.ts file to bootstrap from that module instead.
ritikrishu commentedon Feb 25, 2020
@codemysoul there is no point of SSR, if you only include those in the browser bundle.
ahelmel commentedon Apr 10, 2020
I have a similar issue.
I added
grpcand@grpc/proto-loaderasexternalDependenciesinangular.json.But now on runtime when running
serve:ssrI get the following error:I am using
angular: 9.1.1,firebase: 7.14.0and@angular/fire: 6.0.0.Any ideas?
curiouscod3 commentedon Apr 10, 2020
This is still happening in 9.1
adding grpc stuff in angular.json doesn't work!
hiepxanh commentedon Apr 11, 2020
add this
@firebase/firestoretoexternalDependenciesI already create an PR to clarify that https://github.com/angular/angularfire/pull/2372/files?short_path=e76f33d#diff-e76f33db0439ee8e320dfa7ecf47f09b
hiepxanh commentedon Apr 11, 2020
example repository follow that instruction above here: https://github.com/hiepxanh/angular-fire-universal
and official example using webpack here: https://github.com/angular/angularfire/tree/master/sample
herreraLeonar commentedon May 3, 2020
I fixed error "Element is not defined" deleting "ng-inline-svg": "^8.5.1", in package.json, Angular 9
AnriTapel commentedon Jul 9, 2020
Adding
grpc, @grpc/proto-loader, @firebase/firestoretoexternalDependencieshelped me, so thanks to all of you! Been strugglin' with this issue for three weeks!alan-agius4 commentedon Oct 14, 2022
Thanks for reporting this issue. Luckily, it has already been fixed in one of the recent releases. Please update to the most recent version to resolve the problem.
angular-automatic-lock-bot commentedon Nov 14, 2022
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.