- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 this 的帮助下在 Angular 6 中进行 ssr链接,但显示以下错误
Node server listening on http://localhost:4000
TypeError: StaticInjectorError[InjectionToken Application Initializer -> InjectionToken DocumentToken]:
StaticInjectorError(Platform: core)[InjectionToken Application Initializer -> InjectionToken DocumentToken]:
Right-hand side of 'instanceof' is not an object
server.ts
// These are important and needed before anything else
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import { renderModuleFactory } from '@angular/platform-server';
import { enableProdMode } from '@angular/core';
import * as express from 'express';
import { join } from 'path';
import { readFileSync } from 'fs';
// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();
// Express server
const app = express();
const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), 'dist');
// Our index.html we'll use as our template
const template = readFileSync(join(DIST_FOLDER, 'angular6ssr', 'index.html')).toString();
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main');
const { provideModuleMap } = require('@nguniversal/module-map-ngfactory-loader');
app.engine('html', (_, options, callback) => {
renderModuleFactory(AppServerModuleNgFactory, {
// Our index.html
document: template,
url: options.req.url,
// DI so that we can get lazy-loading to work differently (since we need it to just instantly render it)
extraProviders: [
provideModuleMap(LAZY_MODULE_MAP)
]
}).then(html => {
callback(null, html);
});
});
app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'angular6ssr'));
// Server static files from /browser
app.get('*.*', express.static(join(DIST_FOLDER, 'angular6ssr')));
// All regular routes use the Universal engine
app.get('*', (req, res) => {
res.render(join(DIST_FOLDER, 'angular6ssr', 'index.html'), { req });
});
// Start up the Node server
app.listen(PORT, () => {
console.log(`Node server listening on http://localhost:${PORT}`);
});
Angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular6ssr": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/angular6ssr",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "angular6ssr:build"
},
"configurations": {
"production": {
"browserTarget": "angular6ssr:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "angular6ssr:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
"styles.css"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"server": {
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/server",
"main": "src/main.server.ts",
"tsConfig": "src/tsconfig.server.json"
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
}
}
}
}
},
"angular6ssr-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "angular6ssr:serve"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "angular6ssr"
}
package.json
{
"name": "angular6ssr",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server",
"serve:ssr": "node dist/server.js",
"build:client-and-server-bundles": "ng build --prod && ng build --build-optimizer --aot --environment prod --app 1 --output-hashing=false",
"webpack:server": "webpack --config webpack.server.config.js --progress --colors"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.0",
"@angular/common": "^6.0.0",
"@angular/compiler": "^6.0.0",
"@angular/core": "^6.0.0",
"@angular/forms": "^6.0.0",
"@angular/http": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"@angular/platform-browser-dynamic": "^6.0.0",
"@angular/platform-server": "^6.0.5",
"@angular/router": "^6.0.0",
"@nguniversal/module-map-ngfactory-loader": "^6.0.0",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"ts-loader": "^4.4.1",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.6.0",
"@angular/cli": "~6.0.0",
"@angular/compiler-cli": "^6.0.0",
"@angular/language-service": "^6.0.0",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~1.4.2",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "~2.7.2",
"webpack-cli": "^3.0.8"
}
}
webpack.server.config.js
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: { server: './server.ts' },
resolve: { extensions: ['.js', '.ts'] },
target: 'node',
// this makes sure we include node_modules and other 3rd party libraries
externals: [/(node_modules|main\..*\.js)/],
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js'
},
module: {
rules: [
{ test: /\.ts$/, loader: 'ts-loader' }
]
},
plugins: [
// Temporary Fix for issue: https://github.com/angular/angular/issues/11580
// for "WARNING Critical dependency: the request of a dependency is an expression"
new webpack.ContextReplacementPlugin(
/(.+)?angular(\\|\/)core(.+)?/,
path.join(__dirname, 'src'), // location of your src
{} // a map of your routes
),
new webpack.ContextReplacementPlugin(
/(.+)?express(\\|\/)(.+)?/,
path.join(__dirname, 'src'),
{}
)
]
}
我使用命令“npm run build:ssr”成功创建了应用程序的构建,但是当我尝试启动服务器“npm runserve:ssr”时,它显示了上面的错误。任何人都可以帮我解决吗这个问题?
最佳答案
有关 angular-cli 的问题。您需要在开发模式下使用 webpack 构建服务器。只需将 package.json 脚本更改为:webpack --modedevelopment--config webpack.server.config.js --progress --colors
。不幸的是,我无法详细说明发生了什么,但开发人员已经意识到这个问题并正在努力解决它。
关于angular6 - StaticInjectorError 在角度 6 中执行 ssr 时, 'instanceof' 的右侧不是对象问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50899088/
似乎这是不可能的,但如果有人提示如何在谷歌浏览器中创建右侧边栏(如 iframe),任何提示都会有所帮助。谢谢。 最佳答案 如果你的意思是这样的 这是来自 google chrome 实验 api:
您好,我在用 C 语言解决编程任务时遇到问题。 The funktion "Trim" should replace all spaces at the end of a String with nu
有什么方法可以找到一个事件(或属性或方法或类似的东西)来检测窗口停靠到左侧或右侧吗? 描述: 通过 WindowState 属性,您可以了解当您的窗口在正常/最小化/最大化这三种状态之间改变状态时。在
我目前需要找到一个算法来确定一个点是在圆弧的右侧还是左侧。 这是以下算法的扩展以包含弧: // isLeft(): tests if a point is Left|On|Right of an i
我正在使用 Selenium 执行测试,该测试在 3 个浏览器上并行执行。我想以下一种方式定位 window :左侧,右侧和底部,所以基本上我正在寻找与 (start btn+left btn...)
如果我有下面的代码,并且我想插入一个带有 jquery 的 div 作为表单标记内的第一个元素,那么最好的方法是什么? //i want to insert a div here with
有没有比这个更好的方法来解决这个问题? def 渲染(arr): single_elements = [] double_elements = [] for i in xrange(len(arr
Home About
我遇到的问题是: www.dondolomemories.it 当调整窗口大小时, Logo 图像直到最后一刻才调整大小,导致可怕的两行菜单溢出。 我花了将近 2 个小时尝试大量不同的设置。有人可以帮
我希望我能很好地解释这一点。我有一个 style="float: right;"的 div在这个 div 中,我有一个包含一些编辑器字段的表。但现在我想要两个文本编辑器框(在 .NET MVC3 @H
如果有人能帮助我解决这个问题,我将不胜感激,因为我无法让它工作。 这是我正在努力处理的代码:http://jsfiddle.net/sp91c3nk/ 基本上,我希望右侧导航栏与灰色主要内容区域处于同
我正在尝试在图像的所有四个边上添加文本,但我无法让正确的文本正确对齐。右边的文字仍然在左边。 fiddle :https://jsfiddle.net/y75L0ww9/ Text on top Te
我正在尝试为顶部以及左侧和右侧设置 css 阴影,但高度降低。我熟悉模糊/半径,但我希望阴影非常短。 picture from wix template (还不能上传,抱歉) 有人可以帮帮我吗?我看到
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 6 年前。 Improve
请看这个jsfiddle . 我想要 与 innerText “嗨!”始终出现在其包含父级的可见部分的底部/右侧。它不应与其父级的内容一起滚动。 HTML: Header
我有一个输入框和一个提交按钮。 当我向右浮动提交按钮时,我希望它在与输入字段相同的点结束 - 这是我的意思的一个例子:http://prntscr.com/aggln5 目前,输入和提交在不同的点结束
我基本上刚刚开始让我的网站响应,但出于某种原因,语言 div (#lang) 设置为向右浮动,正在向右浮动,但在它的右侧有一个小边距。虽然没有填充设置父 div #container,但我无法理解。
我目前正在创建一个网站,该网站有一个带有文本等内容的居中框。现在,我还想要一个漂浮在右边的盒子,与我的主盒子有一点缝隙。留个图吧,我画的红框就是我要制作的 float 框。 顺便说一句。蓝色方框只是我
我不是 UI 开发人员,但这次需要玩 css。为用户配置文件编写表单。我快完成了,但还有一个小问题。问题 个人资料图片未正确显示在右侧。 因此,第一个字段(组织名称)显示不正确 自从过去两个小时以来,
我有以下脚本: http://jsfiddle.net/rYFEY/12/ 效果很好,除了我需要移除右侧和右下角的 handle ,只留下底部 handle 用于调整大小。目前,如果我点击右 hand
我是一名优秀的程序员,十分优秀!