node.js - 将我的项目上传到 Heroku 时出现此错误。我正在使用 MapBox 和 node.js
问题描述
嗨,在 Heroku 上上传我的应用程序时,我收到以下错误 - “throw new Error('Cannot create a client without a 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
推荐阅读
- php - 尽管 varchar 长度正确,但 php 中的 password_verify 函数不起作用
- spss - 如何合并来自不同列的 SPSS 变量的内容
- git - 无法推送到 Github:gitmodulesParse: could not parse gitmodules blob
- amazon-web-services - Amazon AWS EC2 - 如何限制仅从弹性负载均衡器接收流量?
- java - 如何在 Spark Streaming 中使用 redis?
- azure-active-directory - Azure 活动目录服务
- python - 在 Python 中将潜在的布尔值转换为布尔值,有什么缺点吗?
- javascript - rxjs v6 / redux-observable v1.0.0:操作员不能在史诗中工作
- pandas - 如何使用非唯一多索引向熊猫数据框添加新行
- ruby - 改进我的正则表达式以包含包含小数和百分号的数字