简体   繁体   English

找不到模块'../dist/ngfactory/src/app/app.server.module.ngf actory'。 角度cli

[英]Cannot find module '../dist/ngfactory/src/app/app.server.module.ngf actory'. angular cli

I wanted to make my angular app seo friendly so I searched google and found several solutions Make your Angular App SEO-Friendly (Angular 4 + Universal) I follow the instructions however when I run the project with npm run start the following error occurred: 我想让我的角度应用程序seo友好所以我搜索谷歌并找到了几个解决方案使你的Angular App SEO友好(Angular 4 + Universal)我按照说明操作但是当我用npm run start运行项目时发生以下错误:

src/server.ts(5,42): error TS2307: Cannot find module '../dist/ngfactory/src/app/app.server.module.ngf
actory'.

I search entire day looking for solution I read this issue [AOT] @ngtools/webpack throws "Cannot find module './ngfactory/app/app.module.ngfactory'" however my problem didn't solve my problem all of my packages are the latest version and this is my build commmand inside package.json 我整天搜索寻找解决方案我读了这个问题[AOT] @ ngtools / webpack throws“找不到模块'./ngfactory/app/app.module.ngfactory'”但是我的问题并没有解决我的问题我的所有包是最新版本,这是我在package.json中的构建命令

"prestart": "ng build --prod && ./node_modules/.bin/ngc",
"start": "ts-node src/server.ts",

here is server.ts file: 这是server.ts文件:

import 'reflect-metadata';
import 'zone.js/dist/zone-node';
import { platformServer, renderModuleFactory } from '@angular/platform-server'
import { enableProdMode } from '@angular/core'
import { AppServerModuleNgFactory } from '../dist/ngfactory/src/app/app.server.module.ngfactory'
import * as express from 'express';
import { readFileSync } from 'fs';
import { join } from 'path';

const PORT = 4200;

enableProdMode();

const app = express();

let template = readFileSync(join(__dirname, '..', 'dist', 'index.html')).toString();

app.engine('html', (_, options, callback) => {
  const opts = { document: template, url: options.req.url };

  renderModuleFactory(AppServerModuleNgFactory, opts)
    .then(html => callback(null, html));
});

app.set('view engine', 'html');
app.set('views', 'src')

app.get('*.*', express.static(join(__dirname, '..', 'dist')));

app.get('*', (req, res) => {
  res.render('index', { req });
});

app.listen(PORT, () => {
  console.log(`listening on http://localhost:${PORT}!`);
});

i don't know if it will help or not but you can Try To Put (./) in "start" : "th-node ./", 我不知道它是否会有所帮助,但你可以试着把(./)置于“开始”:“th-node ./”,

"prestart": "ng build --prod && ./node_modules/.bin/ngc",
"start": "ts-node ./src/server.ts"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 8.2 + Firebase:./src/app/app.module.ngfactory.js 中的 ERROR in ./src/app/app.module.ngfactory.js 错误接近 `ng build --prod` 的过程失败 - Angular 8.2 + Firebase: `ERROR in ./src/app/app.module.ngfactory.js` errors near the end of `ng build --prod` fails the process 在Angular2应用中找不到名称模块 - Cannot find name module in Angular2 app 在我的应用程序上运行“ng serve”时“找不到模块‘@angular/compiler-cli/ngcc’” - "Cannot find module '@angular/compiler-cli/ngcc'" when running "ng serve" on my app Gulp错误:找不到模块'jshint / src / cli' - Gulp Error: Cannot find module 'jshint/src/cli' 找不到模块 /srv/server.js - gcloud 应用引擎 - cannot find module /srv/server.js - gcloud app engine 在现有 Nx 项目上创建 React 应用程序时找不到模块“nx/src/config/workspaces” - Cannot find module 'nx/src/config/workspaces' on creating a React app on existing Nx project 错误 [ERR_MODULE_NOT_FOUND]:找不到从 build\\server.js 导入的模块“build\\app” - Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'build\app' imported from build\server.js 找不到模块:在我的带有节点的应用中 - Cannot find module: in my app with node 运行服务器时找不到模块'../lib/cli'错误 - Cannot find module '../lib/cli' error when running server src / app / app.module.ts(15,15)中的错误:错误TS2304:找不到名称“ ServiceName” - ERROR in src/app/app.module.ts(15,15): error TS2304: Cannot find name 'ServiceName'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM