簡體   English   中英

將我的項目上傳到 Heroku 時出現此錯誤。 我正在使用 MapBox 和 node.js

[英]I am getting this error while uploading my project to Heroku. I am using MapBox and node.js

嗨,在 Heroku 上上傳我的應用程序時,我收到以下錯誤 - “throw new Error('Cannot create a client without an access token');”

const mbxGeocoding = require('@mapbox/mapbox-sdk/services/geocoding');
const geocodingClient = mbxGeocoding({ accessToken: process.env.MAPBOX_TOKEN });

這就是我通過 process.env.MAPBOX_TOKEN 使用 Mapbox 令牌的方式

我的日志文件

2019-12-31T13:18:05.574782+00:00 heroku[web.1]: Starting process with command `npm start`
2019-12-31T13:18:08.114540+00:00 app[web.1]:
2019-12-31T13:18:08.114592+00:00 app[web.1]: > mnb@0.0.0 start /app
2019-12-31T13:18:08.114594+00:00 app[web.1]: > node ./bin/www
2019-12-31T13:18:08.114597+00:00 app[web.1]:
2019-12-31T13:18:09.265365+00:00 app[web.1]: /app/node_modules/@mapbox/mapbox-sdk/lib/classes/mapi-client.js:25
2019-12-31T13:18:09.265398+00:00 app[web.1]: throw new Error('Cannot create a client without an access token');
2019-12-31T13:18:09.265400+00:00 app[web.1]: ^
2019-12-31T13:18:09.265403+00:00 app[web.1]:
2019-12-31T13:18:09.265405+00:00 app[web.1]: Error: Cannot create a client without an access token
2019-12-31T13:18:09.265408+00:00 app[web.1]: at NodeClient.MapiClient (/app/node_modules/@mapbox/mapbox-sdk/lib/classes/mapi-client.js:25:11)
2019-12-31T13:18:09.265410+00:00 app[web.1]: at new NodeClient (/app/node_modules/@mapbox/mapbox-sdk/lib/node/node-client.js:7:14)
2019-12-31T13:18:09.265412+00:00 app[web.1]: at createNodeClient (/app/node_modules/@mapbox/mapbox-sdk/lib/node/node-client.js:24:10)
2019-12-31T13:18:09.265414+00:00 app[web.1]: at /app/node_modules/@mapbox/mapbox-sdk/services/service-helpers/create-service-factory.js:13:16
2019-12-31T13:18:09.265416+00:00 app[web.1]: at Object.<anonymous> (/app/middleware/index.js:7:25)
2019-12-31T13:18:09.265418+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:959:30)
2019-12-31T13:18:09.265423+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
2019-12-31T13:18:09.265425+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:815:32)
2019-12-31T13:18:09.265427+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:727:14)
2019-12-31T13:18:09.265429+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:852:19)
2019-12-31T13:18:09.265431+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2019-12-31T13:18:09.265433+00:00 app[web.1]: at Object.<anonymous> (/app/controllers/index.js:7:32)

包.json

{
  "name": "mnb",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "@mapbox/mapbox-sdk": "^0.5.0",
    "@sendgrid/mail": "^6.3.1",
    "body-parser": "^1.18.3",
    "cloudinary": "^1.13.2",
    "cookie-parser": "~1.4.3",
    "debug": "~4.1.1",
    "dotenv": "^8.2.0",
    "ejs": "~2.6.1",
    "ejs-mate": "^3.0.0",
    "express": "^4.16.4",
    "express-session": "^1.15.6",
    "faker": "^4.1.0",
    "method-override": "^3.0.0",
    "mongoose": "^5.8.3",
    "mongoose-paginate": "^5.0.3",
    "morgan": "^1.9.1",
    "multer": "^1.4.1",
    "multer-storage-cloudinary": "^2.2.1",
    "passport": "^0.4.0",
    "passport-local": "^1.0.0",
    "passport-local-mongoose": "^5.0.1",
    "serve-favicon": "~2.5.0"
  },
  "devDependencies": {
    "nodemon": "^2.0.2"
  }
}

感謝您的幫助!

確保在 .env 文件中聲明 mapbox 令牌時沒有空格

錯誤的:

MAPBOX_TOKEN = ckzsjnzvkqsd,mvlqdf,;ev^q;v

正確的:

MAPBOX_TOKEN=ckzsjnzvkqsd,mvlqdf,;ev^q;v

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM