Angular + Nestjs部署

如何解决Angular + Nestjs部署

我正在尝试使用nestjs和angular开发一个项目。我的项目文件夹是这样的,

项目文件夹

|-服务器(Nestjs应用)

--- |客户端(Angular应用)

--- | ---前

我可以在localhost中运行此应用程序。但是我正在尝试部署到heroku。我构建有角度的应用程序并将这些文件复制到名为front的文件夹中。然后,我将此文件夹拖到服务器文件夹中。

在nestjs应用程序的app.module.ts文件中:

@Module({
 imports: [UserModule,TaskModule,MongooseModule.forRoot(secret.mongoUrl),LoginModule,SignUpModule,ServeStaticModule.forRoot({
    rootPath: join(__dirname,'..','front')
  })
  ],controllers: [AppController],providers: [AppService],})
 

现在,当我通过npm启动我的nestjsapp时,我的angular和nestjs应用程序可以在localhost:3000上完美运行。

这是我的heroku 构建日志

    -----> Node.js app detected
       
-----> Creating runtime environment
       
       NPM_CONFIG_LOGLEVEL=error
       NPM_CONFIG_PRODUCTION=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       NODE_VERBOSE=false
       
-----> Installing binaries
       engines.node (package.json):  unspecified
       engines.npm (package.json):   unspecified (use default)
       
       Resolving node version 12.x...
       Downloading and installing node 12.18.3...
       Using default npm version: 6.14.6
       
-----> Installing dependencies
       Installing node modules (package.json + package-lock)
       
       > bcrypt@5.0.0 install /tmp/build_742df812/node_modules/bcrypt
       > node-pre-gyp install --fallback-to-build
       
       [bcrypt] Success: "/tmp/build_742df812/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node" is installed via remote
       
       > @nestjs/core@7.3.2 postinstall /tmp/build_742df812/node_modules/@nestjs/core
       > opencollective || exit 0
       
       
       > server@0.0.1 postinstall /tmp/build_742df812
       > nest build
       
       client/e2e/src/app.po.ts:1:38 - error TS2307: Cannot find module 'protractor' or its corresponding type declarations.
       
       1 import { browser,by,element } from 'protractor';
                                              ~~~~~~~~~~~~
       client/src/app/add-task/add-task.component.ts:2:39 - error TS2307: Cannot find module '@angular/forms' or its corresponding type declarations.
       
       2 import { FormControl,FormGroup } from '@angular/forms';
                                               ~~~~~~~~~~~~~~~~
       client/src/app/add-task/add-task.component.ts:3:35 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       3 import { Component,OnInit } from '@angular/core';
                                           ~~~~~~~~~~~~~~~
       client/src/app/app-routing.module.ts:7:26 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       7 import { NgModule } from '@angular/core';
                                  ~~~~~~~~~~~~~~~
       client/src/app/app-routing.module.ts:8:51 - error TS2307: Cannot find module '@angular/router' or its corresponding type declarations.
       
       8 import { Routes,RouterModule,CanActivate } from '@angular/router';
                                                           ~~~~~~~~~~~~~~~~~
       client/src/app/app.component.ts:1:27 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       1 import { Component } from '@angular/core';
                                   ~~~~~~~~~~~~~~~
       client/src/app/app.module.ts:2:47 - error TS2307: Cannot find module '@angular/common/http' or its corresponding type declarations.
       
       2 import { HttpClient,HTTP_INTERCEPTORS } from '@angular/common/http';
                                                       ~~~~~~~~~~~~~~~~~~~~~~
       client/src/app/app.module.ts:3:30 - error TS2307: Cannot find module '@angular/router' or its corresponding type declarations.
       
       3 import { RouterModule } from '@angular/router';
                                      ~~~~~~~~~~~~~~~~~
       client/src/app/app.module.ts:4:31 - error TS2307: Cannot find module '@angular/platform-browser' or its corresponding type declarations.
       
       4 import { BrowserModule } from '@angular/platform-browser';
                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
       client/src/app/app.module.ts:5:26 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       5 import { NgModule } from '@angular/core';
                                  ~~~~~~~~~~~~~~~
       client/src/app/app.module.ts:6:33 - error TS2307: Cannot find module '@angular/common/http' or its corresponding type declarations.
       
       6 import {HttpClientModule } from '@angular/common/http'
                                         ~~~~~~~~~~~~~~~~~~~~~~
       client/src/app/app.module.ts:13:49 - error TS2307: Cannot find module '@angular/forms' or its corresponding type declarations.
       
       13 import { FormsModule,ReactiveFormsModule } from '@angular/forms';
                                                          ~~~~~~~~~~~~~~~~
       client/src/app/guards/auth.guard.ts:2:28 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       2 import { Injectable } from '@angular/core';
                                    ~~~~~~~~~~~~~~~
       client/src/app/guards/auth.guard.ts:3:83 - error TS2307: Cannot find module '@angular/router' or its corresponding type declarations.
       
       3 import { CanActivate,ActivatedRouteSnapshot,RouterStateSnapshot,UrlTree } from '@angular/router';
                                                                                           ~~~~~~~~~~~~~~~~~
       client/src/app/home-page/home-page.component.ts:4:35 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       4 import { Component,OnInit } from '@angular/core';
                                           ~~~~~~~~~~~~~~~
       client/src/app/login/login.component.ts:2:35 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       2 import { Component,OnInit } from '@angular/core';
                                           ~~~~~~~~~~~~~~~
       client/src/app/login/login.component.ts:3:39 - error TS2307: Cannot find module '@angular/forms' or its corresponding type declarations.
       
       3 import { FormGroup,FormControl } from '@angular/forms';
                                               ~~~~~~~~~~~~~~~~
       client/src/app/nav-bar/nav-bar.component.ts:1:35 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       1 import { Component,OnInit } from '@angular/core';
                                           ~~~~~~~~~~~~~~~
       client/src/app/services/auth.service.ts:2:34 - error TS2307: Cannot find module '@auth0/angular-jwt' or its corresponding type declarations.
       
       2 import { JwtHelperService } from '@auth0/angular-jwt';
                                          ~~~~~~~~~~~~~~~~~~~~
       client/src/app/services/auth.service.ts:3:28 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       3 import { Injectable } from '@angular/core';
                                    ~~~~~~~~~~~~~~~
       client/src/app/services/auth.service.ts:4:28 - error TS2307: Cannot find module '@angular/common/http' or its corresponding type declarations.
       
       4 import { HttpClient } from '@angular/common/http';
                                    ~~~~~~~~~~~~~~~~~~~~~~
       client/src/app/services/auth.service.ts:5:24 - error TS2307: Cannot find module '@angular/router' or its corresponding type declarations.
       
       5 import { Router } from '@angular/router';
                                ~~~~~~~~~~~~~~~~~
       client/src/app/services/task.service.ts:3:28 - error TS2307: Cannot find module '@angular/common/http' or its corresponding type declarations.
       
       3 import { HttpClient } from '@angular/common/http';
                                    ~~~~~~~~~~~~~~~~~~~~~~
       client/src/app/services/task.service.ts:4:28 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       4 import { Injectable } from '@angular/core';
                                    ~~~~~~~~~~~~~~~
       client/src/app/services/token.interceptor.ts:2:28 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       2 import { Injectable } from '@angular/core';
                                    ~~~~~~~~~~~~~~~
       client/src/app/services/token.interceptor.ts:8:8 - error TS2307: Cannot find module '@angular/common/http' or its corresponding type declarations.
       
       8 } from '@angular/common/http';
                ~~~~~~~~~~~~~~~~~~~~~~
       client/src/app/services/user.service.ts:4:28 - error TS2307: Cannot find module '@angular/common/http' or its corresponding type declarations.
       
       4 import { HttpClient } from '@angular/common/http';
                                    ~~~~~~~~~~~~~~~~~~~~~~
       client/src/app/services/user.service.ts:5:28 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       5 import { Injectable } from '@angular/core';
                                    ~~~~~~~~~~~~~~~
       client/src/app/show-task/show-task.component.ts:2:35 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       2 import { Component,OnInit } from '@angular/core';
                                           ~~~~~~~~~~~~~~~
       client/src/app/show-task/show-task.component.ts:3:30 - error TS2307: Cannot find module '@angular/router' or its corresponding type declarations.
       
       3 import {ActivatedRoute} from '@angular/router';
                                      ~~~~~~~~~~~~~~~~~
       client/src/app/sign-up/sign-up.component.ts:2:40 - error TS2307: Cannot find module '@angular/forms' or its corresponding type declarations.
       
       2 import { FormGroup,FormControl } from '@angular/forms';
                                                ~~~~~~~~~~~~~~~~
       client/src/app/sign-up/sign-up.component.ts:3:35 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       3 import { Component,OnInit } from '@angular/core';
                                           ~~~~~~~~~~~~~~~
       client/src/app/task/task.component.ts:5:35 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       5 import { Component,OnInit } from '@angular/core';
                                           ~~~~~~~~~~~~~~~
       client/src/main.ts:1:32 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       1 import { enableProdMode } from '@angular/core';
                                        ~~~~~~~~~~~~~~~
       client/src/main.ts:2:40 - error TS2307: Cannot find module '@angular/platform-browser-dynamic' or its corresponding type declarations.
       
       2 import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       client/src/test.ts:4:28 - error TS2307: Cannot find module '@angular/core/testing' or its corresponding type declarations.
       
       4 import { getTestBed } from '@angular/core/testing';
                                    ~~~~~~~~~~~~~~~~~~~~~~~
       client/src/test.ts:8:8 - error TS2307: Cannot find module '@angular/platform-browser-dynamic/testing' or its corresponding type declarations.
       
       8 } from '@angular/platform-browser-dynamic/testing';
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       node_modules/ngx-spinner/lib/ngx-spinner.component.d.ts:1:79 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       1 import { OnDestroy,OnInit,OnChanges,SimpleChange,ChangeDetectorRef } from '@angular/core';
                                                                                       ~~~~~~~~~~~~~~~
       node_modules/ngx-spinner/lib/safe-html.pipe.d.ts:1:40 - error TS2307: Cannot find module '@angular/platform-browser' or its corresponding type declarations.
       
       1 import { DomSanitizer,SafeHtml } from '@angular/platform-browser';
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~
       node_modules/ngx-spinner/lib/safe-html.pipe.d.ts:2:31 - error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
       
       2 import { PipeTransform } from '@angular/core';
                                       ~~~~~~~~~~~~~~~
       
       Found 40 error(s).
       
       npm ERR! code ELIFECYCLE
       npm ERR! errno 1
       npm ERR! server@0.0.1 postinstall: `nest build`
       npm ERR! Exit status 1
       npm ERR! 
       npm ERR! Failed at the server@0.0.1 postinstall 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!     /tmp/npmcache.euxxt/_logs/2020-08-25T12_12_21_031Z-debug.log
-----> Build failed
       
       We're sorry this build is failing! You can troubleshoot common issues here:
       https://devcenter.heroku.com/articles/troubleshooting-node-deploys
       
       Some possible problems:
       
       - Node version not specified in package.json
         https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
       
       - A module may be missing from 'dependencies' in package.json
         https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies
       
       Love,Heroku
        !     Push rejected,failed to compile Node.js app.
        !     Push failed

nestjs package.json

 {
  "name": "server","version": "0.0.1","description": "","author": "","private": true,"license": "UNLICENSED","scripts": {
    "prebuild": "rimraf dist","build": "nest build","format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"","start": "nest start","start:dev": "nest start --watch","start:debug": "nest start --debug --watch","start:prod": "node dist/src/main","lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix","test": "jest","test:watch": "jest --watch","test:cov": "jest --coverage","test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand","test:e2e": "jest --config ./test/jest-e2e.json","postinstall": "nest build"
  },"dependencies": {
    "@nestjs/common": "^7.0.0","@nestjs/core": "^7.0.0","@nestjs/mongoose": "^7.0.2","@nestjs/platform-express": "^7.0.0","@nestjs/serve-static": "^2.1.3","bcrpyt": "^2.0.0","bcrypt": "^5.0.0","bootstrap": "^4.5.0","dotenv": "^8.2.0","jsonwebtoken": "^8.5.1","mongoose": "^5.9.25","ngx-spinner": "^10.0.1","reflect-metadata": "^0.1.13","rimraf": "^3.0.2","rxjs": "^6.5.4"
  },"devDependencies": {
    "@nestjs/cli": "^7.0.0","@nestjs/schematics": "^7.0.0","@nestjs/testing": "^7.0.0","@types/express": "^4.17.3","@types/jest": "25.2.3","@types/mongoose": "^5.7.32","@types/node": "^13.9.1","@types/supertest": "^2.0.8","@typescript-eslint/eslint-plugin": "3.0.2","@typescript-eslint/parser": "3.0.2","eslint": "7.1.0","eslint-config-prettier": "^6.10.0","eslint-plugin-import": "^2.20.1","jest": "26.0.1","prettier": "^1.19.1","supertest": "^4.0.2","ts-jest": "26.1.0","ts-loader": "^6.2.1","ts-node": "^8.6.2","tsconfig-paths": "^3.9.0","typescript": "^3.7.4"
  },"jest": {
    "moduleFileExtensions": [
      "js","json","ts"
    ],"rootDir": "src","testRegex": ".spec.ts$","transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },"coverageDirectory": "../coverage","testEnvironment": "node"
  }
}

angular package.json

 {
  "name": "client","version": "0.0.0","scripts": {
    "ng": "ng","start": "ng serve","build": "(if exist ..\\server\\front rmdir ..\\server\\front /s /q) && ng build --prod && move dist/client ..\\server\front","test": "ng test","lint": "ng lint","e2e": "ng e2e","postinstall": "ng build --aot --prod","heroku-postbuild": "ng build --prod"
  },"dependencies": {
    "@angular/animations": "~10.0.6","@angular/common": "~10.0.6","@angular/compiler": "~10.0.6","@angular/core": "~10.0.6","@angular/forms": "~10.0.6","@angular/platform-browser": "~10.0.6","@angular/platform-browser-dynamic": "~10.0.6","@angular/router": "~10.0.6","@auth0/angular-jwt": "^5.0.1","auth0": "^2.27.1","enhanced": "^1.2.1","rxjs": "~6.5.5","tslib": "^2.0.0","zone.js": "~0.10.3"
  },"devDependencies": {
    "@angular-devkit/build-angular": "~0.1000.5","@angular/cli": "~10.0.5","@angular/compiler-cli": "~10.0.6","@types/node": "^12.11.1","@types/jasmine": "~3.5.0","@types/jasminewd2": "~2.0.3","codelyzer": "^6.0.0","jasmine-core": "~3.5.0","jasmine-spec-reporter": "~5.0.0","karma": "~5.0.0","karma-chrome-launcher": "~3.1.0","karma-coverage-istanbul-reporter": "~3.0.2","karma-jasmine": "~3.3.0","karma-jasmine-html-reporter": "^1.5.0","protractor": "~7.0.0","ts-node": "~8.3.0","tslint": "~6.1.0","typescript": "~3.9.5"
  }
}

现在我很困惑,我也不知道该怎么办。任何帮助将非常感谢您的宝贵时间

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-