我找不到一個教程來展示如何做我想做的事情,我已經嘗試混合幾個做類似事情的教程無濟于事。我有一個用 typescript 撰寫的 express 服務器和一個用 typescript 撰寫的 react 應用程式,它們在本地完全按照它們應該的方式運行,但我無法將它們部署到 Heroku。運行 tsc post-install 時構建失敗,錯誤是“找不到模塊”和“沒有 --jsx 標志就不能使用 jsx”的混合。我不確定到底需要改變什么才能讓它發生。
沒有依賴項作為 devdependancies 安裝。在本地運行 tsc 顯示沒有錯誤。
我的 package.json:
{
"name": "inventory",
"version": "1.0.0",
"description": "Odin Project inventory project",
"main": "source/server.ts",
"scripts": {
"client-install": "cd client && npm install",
"start": "node dist/source/server.js",
"server": "cd source && nodemon server.ts",
"client": "cd client && npm start",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"postinstall": "tsc"
},
"repository": {
"type": "git",
"url": "git https://github.com/JonathanDPotter/inventory.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/JonathanDPotter/inventory/issues"
},
"homepage": "https://github.com/JonathanDPotter/inventory#readme",
"dependencies": {
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.13",
"@types/mongoose": "^5.11.97",
"@types/react-router-dom": "^5.3.2",
"concurrently": "^6.4.0",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"mongoose": "^6.0.14",
"react-router-dom": "^6.2.1",
"ts-node": "^10.4.0",
"typescript": "^4.5.4"
},
"engines": {
"node": "16.13.1",
"npm": "7.12.1"
}
}
完整的構建日志很長,但這里有一個示例:
嘗試
npm i --save-dev @types/react-dom它是否存在或添加一個包含declare module 'react-dom';client/src/index.tsx(3,26)的新宣告 (.d.ts) 檔案:錯誤 TS2307:找不到模塊 'react-redux' 或其相應的型別宣告。client/src/index.tsx(6,17): 錯誤 TS6142: 模塊 './App' 已決議為 '/tmp/build_db5fb0f4/client/src/App.tsx',但未設定 '--jsx'。client/src/index.tsx(9,3):錯誤 TS17004:除非提供了“--jsx”標志,否則不能使用 JSX。client/src/index.tsx(10,5): 錯誤 TS17004: 除非提供了“--jsx”標志,否則不能使用 JSX。client/src/index.tsx(11,7): 錯誤 TS17004: 除非提供了“--jsx”標志,否則不能使用 JSX。client/src/store/index.ts(6,8): 錯誤 TS2307: 找不到模塊“@reduxjs/toolkit”或其相應的型別宣告。
在此處鏈接到 GitHub 存盤庫。
uj5u.com熱心網友回復:
我通過添加以下內容解決了這個問題:
"exclude": ["client", "node_modules", "public"]
到 compilerOptions 之后的 tsconfig.json (不在 compilerOptions 中)。
問題的根源在于 tsc 命令也試圖編譯客戶端檔案夾中的所有 React 應用程式。現在它完美地構建。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/400570.html
上一篇:process.env.token不適用于Discordbot啟動
下一篇:Heroku下載資料檔案
