首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类型记录React / NestJS应用程序失败@Heroku构建-“错误TS2307:找不到模块”

类型记录React / NestJS应用程序失败@Heroku构建-“错误TS2307:找不到模块”
EN

Stack Overflow用户
提问于 2021-01-17 14:21:59
回答 1查看 1K关注 0票数 0

我有一个类型记录React/Express应用程序,它在本地和@Heroku都运行得很好。这周我开始学习Nest.JS,所以我用它替换了Express end。该应用程序在本地运行良好,但Heroku构建失败。我浏览了许多主题和指南,但未能找到问题所在,此时,我甚至无法确定问题是在React还是Nest.JS方面。

Heroku的构建进行得很好,并在某一时刻退出了以下工作:

代码语言:javascript
复制
remote: client/src/components/App.tsx:1:19 - error TS2307: Cannot find module 'react' or its corresponding type declarations.
remote: client/src/components/main/Navbar.tsx:3:20 - error TS2307: Cannot find module 'styled-components' or its corresponding type declarations.

基本上,每一个单一的反应,样式组件,路由器,头盔等进口抛回与相同的错误信息。我想这与路径相关,类似的东西,我可以想象解决方案很简单,但我看不见。:/

react tsconfig.json

代码语言:javascript
复制
{
  "compilerOptions": {
    "baseUrl": "./src",
    "target": "es6",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

nestjs tsconfig.json

代码语言:javascript
复制
{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "moduleResolution": "node",
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": ".",
    "incremental": true,
    "jsx": "react-jsx"
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}

react package.json

代码语言:javascript
复制
{
  "name": "project-002",
  "description": "project-002",
  "proxy": "http://127.0.0.1:3001",
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.8",
    "@testing-library/react": "^11.2.3",
    "@testing-library/user-event": "^12.6.0",
    "@types/node": "^14.14.20",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "@types/react-helmet": "^6.1.0",
    "@types/react-router-dom": "^5.1.7",
    "@types/styled-components": "^5.1.7",
    "axios": "^0.21.1",
    "dom": "0.0.3",
    "package": "^1.0.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-ga": "^3.3.0",
    "react-helmet": "^6.1.0",
    "react-router-dom": "^5.2.0",
    "react-scripts": "^4.0.1",
    "styled-components": "^5.1.1",
    "typescript": "^4.1.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

nestjs package.json

代码语言:javascript
复制
{
  "name": "project-002",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "engines": {
    "node": "14.4.0"
  },
  "license": "UNLICENSED",
  "scripts": {
    "prebuild": "rimraf dist",
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "node dist/main.js",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/src/main.js",
    "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"
  },
  "dependencies": {
    "@nestjs/common": "^7.5.1",
    "@nestjs/config": "^0.6.1",
    "@nestjs/core": "^7.5.1",
    "@nestjs/mapped-types": "^0.2.0",
    "@nestjs/platform-express": "^7.5.1",
    "compression": "^1.7.4",
    "helmet": "^4.3.1",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^6.6.3"
  },
  "devDependencies": {
    "@nestjs/cli": "^7.5.1",
    "@nestjs/schematics": "^7.1.3",
    "@nestjs/testing": "^7.5.1",
    "@types/express": "^4.17.8",
    "@types/jest": "^26.0.15",
    "@types/node": "^14.14.6",
    "@types/supertest": "^2.0.10",
    "@typescript-eslint/eslint-plugin": "^4.6.1",
    "@typescript-eslint/parser": "^4.6.1",
    "eslint": "^7.12.1",
    "eslint-config-prettier": "7.1.0",
    "eslint-plugin-prettier": "^3.1.4",
    "jest": "^26.6.3",
    "prettier": "^2.1.2",
    "supertest": "^6.0.0",
    "ts-jest": "^26.4.3",
    "ts-loader": "^8.0.8",
    "ts-node": "^9.0.0",
    "tsconfig-paths": "^3.9.0",
    "typescript": "^4.0.5"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}

有什么好办法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-17 19:47:20

好吧,我发现了我的错误。如果将来有人需要的话,我就把这条线放在一边。

我用了这个脚本:

代码语言:javascript
复制
"heroku-postbuild": "npm install && npm install --only=dev --no-shrinkwrap && npm run build"

但我需要这个

代码语言:javascript
复制
"heroku-postbuild": "cd client && npm install && npm install --only=dev --no-shrinkwrap && npm run build"

一切看起来都很好&现在还不错。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65761736

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档