I've followed several workthroughs https://youtu.be/gxCu5TEmxXE on deploying Angular Universal and am currently doing so on firebase. I've successfully got the server rendering the app, BUT for some reason the app isn't bootstrapping from the server code. What I mean to say, is that when I load the app rendered by the server, the actual app itself doesn't function correctly.
I'm not sure if this is because of incompatibility for example with Angular Material https://github.com/angular/universal#in-progress or if I've made some errors in the configuration.
For example, if I load up my homepage via the normal compiled app and navigate to a form, I see the 'expected' form. However, if I load same page via the server rendering then I see the rendered form but I cannot interact with it.
Rendered form that you cannot interact with
Expected result if you navigate through the app
It feels like I am missing a key part of in the integration to make the server side rendered HTML transition into the normal app. What am I missing to make sure that the server rendered HTML transitions and functions in the same way as the normal app?
app.server.module
import {NgModule} from '#angular/core';
import {ServerModule} from '#angular/platform-server';
import {AppModule} from './app.module';
import {AppComponent} from './app.component';
#NgModule({
imports: [
// The AppServerModule should import your AppModule followed
// by the ServerModule from #angular/platform-server.
AppModule,
ServerModule
],
// Since the bootstrapped component is not inherited from your
// imported AppModule, it needs to be repeated here.
bootstrap: [AppComponent],
})
export class AppServerModule {}
server.ts
import * as functions from 'firebase-functions';
import * as angularUniversal from 'angular-universal-express-firebase';
export let ssrapp = angularUniversal.trigger({
index: __dirname + '/browser/index.html',
main: __dirname + '/server/main.bundle',
enableProdMode: true,
browserCacheExpiry: 1200,
cdnCacheExpiry: 600
});
firebase.json
{
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"function": "ssrapp"
}
]
},
"functions": {
"predeploy": "npm --prefix functions run build",
"source": "functions"
}
}
package.json
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build:client-and-server-bundles": "ng build --prod && ng build --prod --app 1 --output-hashing=false",
"build:prerender": "npm run build:client-and-server-bundles && npm run webpack:server && npm run generate:prerender",
"build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server",
"generate:prerender": "cd dist && node prerender",
"webpack:server": "webpack --config webpack.server.config.js --progress --colors",
"serve:prerender": "cd dist/browser && http-server",
"serve:ssr": "node dist/server"
},
"private": true,
"dependencies": {
"#angular/animations": "^5.1.0",
"#angular/cdk": "5.0.1",
"#angular/common": "^5.1.0",
"#angular/compiler": "^5.1.0",
"#angular/core": "^5.1.0",
"#angular/flex-layout": "git+https://github.com/angular/flex-layout-builds.git",
"#angular/forms": "^5.1.0",
"#angular/http": "^5.1.0",
"#angular/material": "5.0.1",
"#angular/material-moment-adapter": "^5.0.0",
"#angular/platform-browser": "^5.1.0",
"#angular/platform-browser-dynamic": "^5.1.0",
"#angular/platform-server": "^5.2.0-beta.0",
"#angular/router": "^5.1.0",
"#angular/service-worker": "^5.1.0",
"#nguniversal/express-engine": "^5.0.0-beta.5",
"#nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.5",
"#types/moment": "^2.13.0",
"angular-ssr": "^0.10.40",
"angular2-universal": "^2.1.0-rc.1",
"body-parser": "^1.18.2",
"braintree-web": "^3.26.0",
"core-js": "^2.4.1",
"moment": "^2.20.1",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
},
Related
When I try to run npm run generate it is giving me this error
It should generate the static nuxtjs site.
Before it was on Nuxt-3-rc and it was building site successfully. As I converted it to Nuxt 3.0 Stable it is giving me this error.
Package.json
{
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"start": "nuxt dev",
"generate": "nuxt generate ",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"vite:build": "vite build"
},
"devDependencies": {
"#fortawesome/free-brands-svg-icons": "^6.2.0",
"#fortawesome/free-solid-svg-icons": "^6.2.0",
"#nuxt/postcss8": "^1.1.3",
"#nuxtjs/fontawesome": "^1.1.2",
"#nuxtjs/tailwindcss": "^5.3.3",
"#tailwindcss/forms": "^0.5.3",
"autoprefixer": "^10.4.13",
"nuxt": "3.0.0",
"postcss": "^8.4.19",
"tailwindcss": "^3.2.4"
},
"dependencies": {
"#a1ter/nuxt-auth-aws-cognito-scheme": "^0.0.12",
"#headlessui/vue": "^1.4.2",
"#mdi/js": "^7.0.96",
"#nuxtjs/auth-next": "^5.0.0-1637745161.ea53f98",
"#pinia/nuxt": "^0.4.2",
"amazon-cognito-identity-js": "^5.2.10",
"aws-amplify": "^4.3.21",
"chart.js": "^3.9.1",
"numeral": "^2.0.6",
"pinia": "^2.0.22",
"readable-stream": "^4.2.0",
"rollup-plugin-node-polyfills": "^0.2.1"
}
}
I found the solution.
I am using AWS sdk with nuxt 3 which is causing issues.
In Nuxt.config file instead of
vite: {
resolve: {
alias: {
'./runtimeConfig': './runtimeConfig.browser'
}
},
// temp-fix for dev, it breaks build for now (see: https://github.com/nuxt/framework/issues/4916)
define: {
global: {}
}
},
Using this would help. Github Issue
vite: {
resolve: {
alias: {
'./runtimeConfig': './runtimeConfig.browser'
}
},
// temp-fix for dev, it breaks build for now (see: https://github.com/nuxt/framework/issues/4916)
define: {
'window.global': {}
}
},
I have done everything in accordance with the docs.
I installed storybook, and then I changed the config file the way they say has to be done to make storybook work on Vite, which supports the element-plus library.
.storybook/main.js:
module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.#(js|jsx|ts|tsx)'],
addons: ['#storybook/addon-links', '#storybook/addon-essentials'],
core: {
builder: '#storybook/builder-vite', // 👈 The builder enabled here.
},
}
Package.json:
{
"name": "elementui-practice",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview --port 4173",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
"dependencies": {
"element-plus": "^2.2.17",
"node-sass": "^7.0.3",
"sass-loader": "^13.0.2",
"vue": "^3.2.38"
},
"devDependencies": {
"#babel/core": "^7.19.1",
"#storybook/addon-actions": "^6.5.12",
"#storybook/addon-essentials": "^6.5.12",
"#storybook/addon-interactions": "^6.5.12",
"#storybook/addon-links": "^6.5.12",
"#storybook/builder-vite": "^0.2.2",
"#storybook/testing-library": "^0.0.13",
"#storybook/vue3": "^6.5.12",
"#vitejs/plugin-vue": "^3.0.3",
"babel-loader": "^8.2.5",
"eslint": "^8.23.1",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-storybook": "^0.6.4",
"eslint-plugin-vue": "^9.5.1",
"sass": "^1.55.0",
"vite": "^3.0.9",
"vue-cli-plugin-storybook": "~2.1.0",
"vue-loader": "^16.8.3"
}
}
If I run only the element-plus (npm run dev), the library works.
If I run npm run storybook, element-plus styles are not applied to the components or elements. Normal css works, but element-plus components and styles do not work.
Add these code to storybook's preview.js
import { app } from '#storybook/vue3'; //I use Vue3
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
app.use(ElementPlus);
I am trying to import one of my local vue library component in vue project. Created library components and installed in project using npm install dialogue-box-0.1.0.tgz, its a local vue library not published to npm.
Below is library package.json
{
"name": "dialogue-box",
"version": "0.1.0",
"private": false,
"main": "dist/dialogue-box.common.js",
"files": ["dist/*", "types/*"],
"types": "./types/index.d.ts",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"build-lib": "vue-cli-service build --target lib --name dialogue-box './src/index.js' && npm pack",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.5",
"vue": "^2.6.11"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-service": "~4.5.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
Below is the index.js file of my library
import App from './App.vue'
import AlertComponent from './components/AlertComponent.vue';
import HelloWorld from './components/HelloWorld.vue';
export default {
App,
AlertComponent,
HelloWorld
}
Created index.d.ts stating as below
declare module "dialogue-box";
When i imported the HelloWorld Component in my actual project template and ran server getting below error.
enter image description here
Issue with not properly configured to a library.
Please use below link, have configured properly and able to integrate the local build vue library to any other vue project.Follow the Readme in git to configure in any project.
https://github.com/MohanaDevarasetty/dialogue-box.git
I am getting a persistent Jest error whenever I use npm to install my dependencies on the server side. Using yarn to install the same dependencies works, but I am currently working on a team where we're all using npm. I have tried all of the proposed solutions on Stack Overflow, upvoted or not, and none have worked for me. The two senior devs I've asked so far don't think there is anything in my globally installed npm packages that would cause this.
I get this error for every Jest test suite I run:
● Test suite failed to run
Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of #babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error tolook for the first entry that doesn't mention "#babel/core" or "babel-core" to see what is calling Babel.
at throwVersionError (node_modules/#babel/helper-plugin-utils/lib/index.js:65:11)
at Object.assertVersion (node_modules/#babel/helper-plugin-utils/lib/index.js:13:11)
at _default (node_modules/#babel/plugin-proposal-decorators/lib/index.js:35:7)
at node_modules/#babel/helper-plugin-utils/lib/index.js:19:12
at Function.memoisePluginContainer (../../../node_modules/babel-core/lib/transformation/file/options/option-manager.js:113:13) at Function.normalisePlugin (../../../node_modules/babel-core/lib/transformation/file/options/option-manager.js:146:32) at ../../../node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
at Array.map (<anonymous>)
at Function.normalisePlugins (../../../node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (../../../node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at OptionManager.init (../../../node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (../../../node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (../../../node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (../../../node_modules/babel-core/lib/transformation/pipeline.js:46:16)
This is what my package.json looks like:
{
"name": "nanny-now",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest --verbose --runInBand",
"test:watch": "npm run test -- --watch",
"build": "babel src -d lib -s true",
"start": "node lib/index.js",
"start:watch": "nodemon src/index.js --exec babel-node"
},
"jest": {
"testEnvironment": "node"
},
"repository": {
"type": "git",
"url": ""
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.1.5",
"#babel/core": "^7.2.0",
"#babel/node": "^7.0.0",
"#babel/plugin-proposal-class-properties": "^7.1.0",
"#babel/plugin-proposal-decorators": "^7.1.6",
"#babel/plugin-syntax-dynamic-import": "^7.0.0",
"#babel/preset-env": "^7.1.6",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"chance": "^1.0.18",
"eslint": "^5.9.0",
"eslint-plugin-babel": "^5.3.0",
"jest": "^23.6.0",
"nodemon": "^1.18.7",
"supertest": "^3.3.0"
},
"dependencies": {
"bcryptjs": "^2.4.3",
"dotenv": "^6.2.0",
"express": "^4.16.4",
"jsonwebtoken": "^8.4.0",
"mongoose": "^5.3.14",
"morgan": "^1.9.1",
"regenerator-runtime": "^0.13.1"
}
}
Here is my .babelrc file:
{
"presets": [
"#babel/preset-env"
],
"plugins": [
[
"#babel/plugin-proposal-decorators",
{
"decoratorsBeforeExport": true
}
],
"#babel/plugin-proposal-class-properties"
]
}
As George Artemiou says, this error occurs because you are using Babel 7 in your project, while jest still uses Babel 6.
I had the same issue, and I solved it by installing babel-core#^7.0.0-bridge.0
See also:
https://github.com/babel/babel-bridge
The problem is with jest dependencies. I had the same issue and resolved it by adding the step below to my package.json file
"scripts": {
...
"postinstall": "rimraf node_modules/jest-runtime/node_modules/babel-core node_modules/jest-config/node_modules/babel-core",
...
}
Hope this helps..
Preface: I am new to Javascript, Babel and React-Native.
I have been developing my app using the TodoMVC example from the relay source. I was wondering if it's possible to get React-Native + Relay to work together easily?
I setup my babelRelayPlugin and added it to my .babelrc. I installed the npm packages for "react-relay":"^0.7.3" and "babel-relay-plugin": "^0.7.3" but after running "npm install" and "react-native start" I either get an error saying "Unrecognized module 'react-relay'" OR "Relay is not defined".
From reading this thread and looking at the last comment ( https://github.com/facebook/relay/issues/26#issuecomment-194570137 ) it looks like at the moment I should just use TodoMVC as my base for new React-Native + Relay projects.
Is this correct?
Here is my .babelrc
{
"env": {
"development": {
"passPerPreset": true,
"presets": [
{
"plugins": [
"./plugins/babelRelayPlugin"
]
},
"react-native"
]
},
"server": {
"plugins": [
"./plugins/babelRelayPlugin"
],
"presets": [
"es2015",
"stage-0"
]
}
}
}
Here is my package.json
{
"name": "testApp",
"version": "1.0.0",
"private": true,
"scripts": {
"clean:babelrc": "find ./node_modules -name react-packager -prune -o -name '.babelrc' -print | xargs rm -f",
"postinstall": "npm run clean:babelrc",
"start": "BABEL_ENV=server babel-node ./server.js",
"update-schema": "babel-node ./scripts/updateSchema.js"
},
"dependencies": {
"babel-preset-es2015": "^6.5.0",
"babel-preset-react-native": "^1.5.1",
"babel-preset-stage-0": "^6.5.0",
"babel-relay-plugin": "^0.7.3",
"express": "4.13.4",
"express-graphql": "0.4.9",
"graphql": "0.4.17",
"graphql-relay": "0.3.6",
"moment": "^2.12.0",
"node-fetch": "^1.4.1",
"react": "^0.14.5",
"react-native": "^0.22.2",
"react-native-animatable": "^0.5.2",
"react-native-aws3": "0.0.1",
"react-native-camera": "git+https://github.com/lwansbrough/react-native-camera.git",
"react-native-console-panel": "0.0.7",
"react-native-contacts": "^0.2.3",
"react-native-keyboard-aware-scroll-view": "0.0.6",
"react-relay": "^0.7.3",
"sync-request": "^3.0.0",
"uuid-v4": "^0.1.0"
},
"devDependencies": {
"babel-cli": "^6.6.4",
"flow-bin": "^0.22.1"
},
"engines": {
"npm": ">=3"
}
}
I managed to fix the issue. I added "babel-core": "^6.7.6" as a dev dependency. Removed all the scripts and cloned the project from git to a new folder. Everything runs perfectly now!