小编Gou*_*raj的帖子

因为它的MIME类型('text/html')不可执行,并且启用了严格的MIME类型检查

我正在使用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.
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

/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){ …
Run Code Online (Sandbox Code Playgroud)

node.js

10
推荐指数
2
解决办法
1万
查看次数

标签 统计

node.js ×1