javascript - 静态快递不提供简单的html页面
问题描述
敲我的脑袋……不是 Javascript 的专业人士,但通常经验丰富,足以让事情顺利进行。这次不是,我不明白为什么:
节点:8.15.1 Npm:6.13.7
更新:这里的 jslib 只是一个示例名称(实际上它是一个商业 3rd 方库),实际上不是 jslib。
包.json:
{
"name": "mytest",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"jslib": "file:../path_to_local_lib/lib/es-modules"
}
}
server.js:
const express = require('express');
const app = express();
app.use(express.static(__dirname + '/public'));
const port = 8000;
app.listen(port, function() {
console.log('server listening on port ' + port)
});
在我的 /public 文件夹中,我有一个 index.html 和一个 basegraph.js:
索引.html:
<!DOCTYPE html>
<html lang="de">
<head>
<link rel="stylesheet" href="../node_modules/lib/lib.css">
</head>
<body>
<div id="graphComponent"></div>
<script type="module" crossorigin="anonymous" src="basegraph.js"></script>
</body>
</html>
和 basegraph.js:
import { GraphComponent } from 'jslib'
const graphComponent = new GraphComponent('#graphComponent');
现在npm install
运行没有问题,npm start
在端口 8000 上启动服务器,但在我的浏览器中打开它会导致:
拒绝应用来自 ' http://localhost:8000/node_modules/lib/lib.css ' 的样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查。
所以我想我对静态快递有问题吗?但我不明白。
第二:
未捕获的类型错误:无法解析模块说明符“jslib”。相对引用必须以“/”、“./”或“../”开头。
那么我在这里做错了什么?:-(
解决方案
推荐阅读
- excel - 如何点击退出组合框?
- docker - Github Actions 云托管运行器,容器中的容器?
- python - 确定 ARIMA 中网格搜索的参数范围 (p,d,q)
- algorithm - 为什么基数较低时基数排序需要更多时间?
- arrays - 如何返回一系列公式中的第一个非空白单元格?
- python-3.x - 通过循环将列添加到空 DataFrame
- vb.net - 如何在 vb .net 中显示 mp3 音乐的同步歌词?
- c - 为什么一个函数有多个指针?
- binaryfiles - PeakTech 1330 示波器的二进制格式
- bundle - 如何让 Spotlight 在其内容被修改后重新索引文档包?