在now.sh上部署时,Express js不会加载node_modules

我使用express创建一个简单的webrtc应用程序,并使用npm start将其工作节点本地化,但是当我部署到now.sh时,我的应用程序无法从node_modules加载任何脚本

我的server.js / index.js

const express = require('express');

const app = express();
const port = 8000;

// Set public folder as root
app.use(express.static(__dirname +'/public'));

// Provide access to node_modules folder from the client-side
app.use('/scripts',express.static(`${__dirname}/node_modules`));

// Redirect all traffic to index.html
app.route('/*').get((req,res) => res.sendFile(`${__dirname}/public/index.html`));

app.listen(port,() => {
  console.info('listening on %d',port);
});

package.json

 {
  "name": "webrtc","version": "1.0.0","description": "","main": "index.js","dependencies": {
    "@andyet/simplewebrtc": "^1.16.0","express": "^4.17.1","handlebars": "^4.7.3","jquery": "^3.4.1","semantic-ui-css": "^2.4.1","simplewebrtc": "^3.0.2"
  },"devDependencies": {},"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1","start": "node index.js"
  },"keywords": [],"author": "good","license": "ISC"
}

now.json

{
    "version": 2,"builds": [{ "src": "index.js","use": "@now/node-server" }]
}
tsm1010 回答:在now.sh上部署时,Express js不会加载node_modules

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2632030.html

大家都在问