- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在处理一个项目,将其更新到 Angular 6。更新后,我现在在尝试运行服务器端渲染构建时遇到此错误
Module not found: Error: Can't resolve './dist/server/main.bundle'
我试着去 https://angular.io/guide/universal并将我的代码与 Angular Universal 中的 SSR 文件进行匹配。这对我不起作用。
dist 文件夹似乎没有生成/server 文件夹,而是创建了/browser。我不确定为什么。
这是我的 angular.json 文件
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"xilo": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/browser",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"assets": [
"src/assets",
"src/favicon.ico"
],
"styles": [
"src/styles.css",
"node_modules/font-awesome/css/font-awesome.min.css"
],
"scripts": [
"node_modules/moment/min/moment.min.js"
]
},
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "xilo:build"
},
"configurations": {
"production": {
"browserTarget": "xilo:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "xilo:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"karmaConfig": "./karma.conf.js",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"scripts": [
"node_modules/moment/min/moment.min.js"
],
"styles": [
"src/styles.css",
"node_modules/font-awesome/css/font-awesome.min.css"
],
"assets": [
"src/assets",
"src/favicon.ico"
]
}
},
"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": "main.server.ts",
"tsConfig": "tsconfig.server.json"
}
}
}
},
"xilo-e2e": {
"root": "",
"sourceRoot": "e2e",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "./protractor.conf.js",
"devServerTarget": "xilo:serve"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"e2e/tsconfig.e2e.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "xilo",
"schematics": {
"@schematics/angular:class": {
"spec": false
},
"@schematics/angular:component": {
"spec": false,
"inlineStyle": true,
"inlineTemplate": true,
"prefix": "app",
"styleext": "css"
},
"@schematics/angular:directive": {
"spec": false,
"prefix": "app"
},
"@schematics/angular:guard": {
"spec": false
},
"@schematics/angular:module": {
"spec": false
},
"@schematics/angular:pipe": {
"spec": false
},
"@schematics/angular:service": {
"spec": false
}
}
}
服务器.ts
// These are important and needed before anything else
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import { enableProdMode } from '@angular/core';
import * as express from 'express';
import { join } from 'path';
// 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');
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/server/main.bundle');
// Express Engine
import { ngExpressEngine } from '@nguniversal/express-engine';
// Import module map for lazy loading
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';
app.engine('html', ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP)
]
}));
app.set('view engine', 'html');
app.set('views', join(DIST_FOLDER, 'browser'));
// TODO: implement data requests securely
app.get('/api/*', (req, res) => {
res.status(404).send('data requests are not supported');
});
// Server static files from /browser
app.get('*.*', express.static(join(DIST_FOLDER, 'browser')));
// All regular routes use the Universal engine
app.get('*', (req, res) => {
res.render('index', { req });
});
// Start up the Node server
app.listen(PORT, () => {
console.log(`Node server listening on http://localhost:${PORT}`);
});
一切都完全按照 Angular Universal 的方向设置。
有人知道为什么我的构建脚本不会生成/server 文件夹吗?
"build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server"
包.json
{
"name": "XXX",
"version": "XXX",
"license": "MIT",
"repository": {
"type": "git",
"url": "XXXXX"
},
"engines": {
"node": "10.7.0",
"npm": "6.1.0"
},
"scripts": {
"ng": "ng",
"start": "node dist/server",
"build": "ng build",
"build:client-and-server-bundles": "ng build --prod && ng build --prod --project xilo --output-hashing=all",
"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",
"deploy": "git push origin master && git push heroku master",
"generate:prerender": "cd dist && node prerender",
"postinstall": "npm run build:ssr",
"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": "6.1.0",
"@angular/common": "6.1.0",
"@angular/compiler": "6.1.0",
"@angular/compiler-cli": "6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "6.1.0",
"@angular/http": "6.1.0",
"@angular/language-service": "6.1.0",
"@angular/platform-browser": "6.1.0",
"@angular/platform-browser-dynamic": "6.1.0",
"@angular/platform-server": "6.1.0",
"@angular/router": "6.1.0",
"@nguniversal/express-engine": "^5.0.0-beta.5",
"@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.5",
"@nicky-lenaers/ngx-scroll-to": "^0.5.0",
"@types/moment": "^2.13.0",
"@types/node": "^8.10.21",
"angular-file": "^0.4.1",
"angular2-moment": "^1.9.0",
"classlist.js": "^1.1.20150312",
"core-js": "^2.5.7",
"cpy-cli": "^1.0.1",
"express": "^4.16.3",
"font-awesome": "^4.7.0",
"http-server": "^0.10.0",
"moment": "^2.22.2",
"ng-circle-progress": "^0.9.9",
"ng-hotjar": "0.0.13",
"ng-intercom": "^1.0.0-beta.5-2",
"ng2-google-charts": "^3.4.0",
"ng4-geoautocomplete": "^0.1.0",
"ngx-filter-pipe": "^1.0.2",
"ngx-loading": "^1.0.14",
"ngx-pagination": "^3.0.3",
"reflect-metadata": "^0.1.10",
"rxjs": "^6.2.2",
"rxjs-compat": "^6.2.2",
"ts-loader": "^4.4.2",
"typescript": "2.9.2",
"web-animations-js": "^2.3.1",
"zone.js": "^0.8.20"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.6.8",
"@angular/cli": "^6.0.8",
"webpack-cli": "^3.1.0"
}
}
最佳答案
它自己说的错误是缺少什么,SSR 构建需要 main.bundle.js所以更新 package.json
中的命令并运行构建 main.bundle.js 的命令
"build:client-and-server-bundles": "ng build --prod && ng run defaultProject:server && npm run webpack:server"
defaultProject
名称可以从 angular.json 文件中找到。然后运行
"serve:ssr": "node dist/careercontroller/server/main.bundle.js"
关于Angular 6 服务器端错误 : Module not found: Error: Can't resolve './dist/server/main.bundle' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51604995/
在基于 Dist::Zilla 的发行版中,我想要一些仅用于测试但不安装的文件。这些是运行时不需要的模型库。 我该怎么做? 最佳答案 CPAN 发行版从不安装 t 和 xt 目录。您可以将测试和模拟库
想要编写适用于多个 Linux 发行版的脚本。还想添加检查命令,如果不存在则安装一些软件包。因此,需要一个解决方案来检查 Dist 名称(如 Debian 或 RedHat)以为此 Dist 执行正确
我正在处理我的 Net::Prober分发,使用 dzil .从下一个版本开始,我想强制执行 perl 5.10+ 的最低要求(是 5.006),因为我使用的是命名捕获 :-) 现在我放了use 5.
您的文件夹的首选标记方法是什么,以区分原始 Assets 和使用任务运行器缩小、连接等的 Assets ?我见过一堆组合,最受欢迎的是src and dist , src and build , de
运行此命令后“wwwroot/dist”和“ClientApp/dist”文件夹有什么区别以及如何正确使用它们? dotnet publish -c Release 最佳答案 wwwroot/dist
我刚刚升级到 cabal 1.22.0.0。我创建了一个全新沙箱,并添加了另一个本地包的链接,如下所示: cabal sandbox add-source /home/amy/néal/créatúr
我有一个使用 Universal 的 Anugular 6 应用程序。 通用/服务器端渲染在本地工作。 我想知道如何将此应用程序部署到 azure 。考虑到它有两个 dist 文件夹(dist、dis
我已经提取了以前在另一台计算机上运行的现有 ASP.NET Core 应用程序。 当我在这台计算机上运行应用程序时,出现以下错误: AggregateException: One or more er
我试图将我的 Angular 5 代码迁移到 Angular 6。 执行 npm 后开始出现以下问题 npm start WARNING in ./node_modules/pdfjs-
/~/@ReMix-Run/Router/dist/router.cjs.js模块分析失败:/HOME/sharib/Desktop/Full Stack Developer Tutorial/MER
我正在尝试启动并运行 J2ME Polish 示例项目,但很困难。 我正在使用带有 J2ME Polish 插件的 Netbeans 8.0.2。 当我尝试创建 J2ME Polish 项目 ( Fi
Bable 只能生成 js 文件(在 dist 文件夹中),而不生成项目目录中的其他文件(如 html、css ..)。我正在使用“build”:“babel source -d dist”。 最佳答
我需要帮助,因为我在过去 2-3 天试图解决这个问题.. 我正在 Windows-7(64 位)机器上设置 Hadoop。这是为了尝试R与Hadoop的集成。 我按照 URL - http://www
我正在尝试了解gradle的分布。在7.3.3.4节 gradle documentation 中,有以下代码示例: task dist(type: Zip) { dependsOn spiJ
我想在分发期间复制一个装满 Assets 的文件夹到我的可执行文件旁边。我如何在 .cabal 文件(或者 Setup.hs)中表示它? 目录结构: root/ dist/ -- Genera
我正在构建一个自己的工具来编译相关的js文件(用ES6编写)并将其打包到一个包中。到目前为止,它与本地文件的预期一致,但是当我涉及公共(public)模块时,例如,react 和 redux 等,情况
我正在使用 gulp 为我的 Angular 应用构建分发 (dist) 文件夹。 所以我已经收集了所有 Controller /服务 JS 文件以及我的 CSS,现在我需要处理 bower 文件夹的
我有两个带有元组(坐标)的列表,例如: some_pt1 = [(10.76,2.9),(3.24,4.28),(7.98,1.98),(3.21,9.87)] some_pt2 = [(11.87,
注意 我是新手,刚刚通过编写这段代码“吹嘘”我的方式 我在用什么 - Angular(使用 Angular Cli) - 火力基地 问题/疑虑 当我运行“ng build --watch”时,它会创建
我的大多数 JavaScript 项目都有一个包含源文件的文件夹 lib 和一个包含项目构建的文件夹 dist。 我使用 WebStorm(很棒的 IDE!),并且 WebStorm 的代码检查器和代
我是一名优秀的程序员,十分优秀!