如果使用Babel和ES6,如何将应用程序部署到Heroku?

问题描述 投票:0回答:1

我为将应用程序部署到Heroku感到头疼。问题是我在Babel中使用ES6

我发现了很多有关此的文章,但没有一篇能帮助我解决问题

即使在本地构建应用程序并尝试运行它时,我也遇到另一个问题-构建文件夹中模块的路径与Babel-build进行编译之前的路径相同这是普通的行为,因为我以前从未遇到过

它应该启动GraphQL API-“ heroku_path / graphql”

[感谢您的帮助...

package.json

{
  "name": "cocoon-api",
  "version": "1.0.0",
  "description": "",
  "private": true,
  "main": "src/server.js",
  "scripts": {
    "dev": "babel-watch src/server.js",
    "clean": "rm -rf build && mkdir build",
    "build-babel": "babel -d ./build ./src -s",
    "build": "npm run clean && npm run build-babel",
    "start": "npm run build && node ./build/server.js",
    "heroku-postbuild": "npm install"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "apollo-server-express": "^2.9.14",
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "graphql": "^14.5.8",
    "graphql-depth-limit": "^1.1.0",
    "graphql-iso-date": "^3.6.1",
    "graphql-middleware": "^4.0.2",
    "graphql-shield": "^7.0.6",
    "graphql-tag": "^2.10.1",
    "graphql-toolkit": "^0.7.5",
    "graphql-tools": "^4.0.6",
    "jsonwebtoken": "^8.5.1",
    "lodash": "^4.17.15",
    "merge-graphql-schemas": "^1.7.4",
    "mongoose": "^5.8.3",
    "winston": "^3.2.1"
  },
  "devDependencies": {
    "@babel/cli": "^7.7.7",
    "@babel/core": "^7.7.7",
    "@babel/node": "^7.7.7",
    "@babel/preset-env": "^7.7.7",
    "babel-plugin-import-graphql": "^2.7.0",
    "babel-watch": "^7.0.0",
    "dotenv": "^8.2.0",
    "nodemon": "^2.0.2"
  }
}

部署错误

$ git push heroku master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 344 bytes | 344.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NPM_CONFIG_PRODUCTION=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:        NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  unspecified
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version 12.x...
remote:        Downloading and installing node 12.16.1...
remote:        Using default npm version: 6.13.4
remote:
remote: -----> Restoring cache
remote:        - node_modules
remote:
remote: -----> Installing dependencies
remote:        Installing node modules (package.json + package-lock)
remote:        audited 7150 packages in 8.044s
remote:
remote:        13 packages are looking for funding
remote:          run `npm fund` for details
remote:
remote:        found 143 low severity vulnerabilities
remote:          run `npm audit fix` to fix them, or `npm audit` for details
remote:
remote: -----> Build
remote:        Detected both "build" and "heroku-postbuild" scripts
remote:        Running heroku-postbuild
remote:
remote:        > [email protected] heroku-postbuild /tmp/build_900f276e6b5aac117b7994386823a0a9
remote:        > npm install
remote:
remote:        audited 7150 packages in 8.008s
remote:
remote:        13 packages are looking for funding
remote:          run `npm fund` for details
remote:
remote:        found 143 low severity vulnerabilities
remote:          run `npm audit fix` to fix them, or `npm audit` for details
remote:
remote: -----> Caching build
remote:        - node_modules
remote:
remote: -----> Pruning devDependencies
remote:        Skipping because NPM_CONFIG_PRODUCTION is 'false'
remote:
remote: -----> Build succeeded!
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 31.5M
remote: -----> Launching...
remote:        Released v11
remote:        https://aqueous-springs-82481.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/aqueous-springs-82481.git
   5cd7f10..4abee83  master -> master

路径错误

Successfully compiled 29 files with Babel.
internal/modules/cjs/loader.js:613
    throw err;
    ^

Error: Cannot find module '../environment'
Require stack:
- C:\Users\Валерий\Documents\Projects\cocoon-api\build\server.js

结构

enter image description here

Procfile

web: npm run start

javascript node.js heroku ecmascript-6 babel
1个回答
0
投票

[您的server.js文件似乎与/environment在同一目录中。

但是您指定的从server.js/environment的路径应该只有一个句点。将../environment更改为./environment

© www.soinside.com 2019 - 2024. All rights reserved.