【发布时间】:2018-08-20 12:05:02
【问题描述】:
我正在使用 nodejs 和 webpack4,我正在尝试将 main.js 文件链接到 index.html。我尝试了网络上所有可能的解决方案,但它们似乎都不适合我。我是新手,欢迎提出建议请让我知道我做错了什么。
这是我看到的错误日志:
GET http://localhost:3000/dist/main.js net::ERR_ABORTED
localhost/:1
Refused to execute script from 'http://localhost:3000/dist/main.js'
because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
public/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
</head>
<body>
<form action="/" method="POST" accept-charset="utf-8">
<input type="email" name="email" placeholder="Email">
<input type="submit" name="submit">
</form>
<script type="text/javascript" src="dist/main.js"> </script>
</body>
</html>
/app.js
const express = require('express');
const app = express();
const http = require('http');
//Middleware
app.use(express.static(__dirname + '/public' ));
app.post('/', function( req ,res){
res.send("Success");
});
app.listen(3000, function(){
console.log('Server running on port 3000');
});
文件结构
news_letter //Root directory
|_ dist
| |_ main.js
|_ public
| |_ index.html
|_ src
| |_ index.js
|_ app.js
【问题讨论】:
标签: node.js