带有es6模块的基本应用无法运行Chrome-ERR_ABORTED 404(未找到)

时间:2019-06-17 21:15:04

标签: reactjs es6-modules

我正在使用es6模块创建一个基本应用程序,并对节点服务器做出反应。 index.html将index.js文件作为模块提供,但未加载该模块,并且控制台显示错误: GET http://localhost:3000/index.js net :: ERR_ABORTED 404(未找到)

https://codesandbox.io/embed/veriz-210fb

https://github.com/stanleyjohnson/veriz

要复制:克隆回购,npm i,npm开始,请转到http://localhost:3000

1 个答案:

答案 0 :(得分:0)

您应通过将以下行添加到server.js文件中来启用static files serving

app.use('/', express.static(__dirname + '/'));

因此您的文件应如下所示:

const express = require('express')
const app = express()
const port = 3000

app.use('/', express.static(__dirname + '/'));

app.get('/', function(req, res) {
    res.sendFile('index.html',{ root: __dirname });
});

app.listen(port);