簡體   English   中英

我無法從節點網站導入點亮的HTML

[英]Way Cant i import lit HTML from a node website

嗨,我正在嘗試學習node的一個小項目,我有一個node get request,它讀取了主頁HTML文件,然后將其發送,

在HTML站點上,我有一個腳本標簽(帶有type = module),並且在腳本的開始階段即導入了lit-HTML模塊,但它卻使整個腳本標簽有效,我該如何解決呢? 節點代碼:

if (req.method === "GET") {     console.log(req.url);   switch (req.url) {  case '/' :      res.writeHead(200,{"Content-Type": "text/html"})        fs.createReadStream("index.html","UTF-8").pipe(res);    break; 

case '/lit-html.js':    var file = fs.readFileSync('lib/lit-html.mjs','UTF-8')  res.writeHead(200,{"Content-Type": "application/javascript"})   res.end(file); break;

這是在index.html中

<script type="module" src="localhost:8000/lit-html.js"></script> <script> import {html, render} from 'localhost:8000/lit-html.js';

這是在節點中

if (req.method === "GET") {     console.log(req.url);   switch (req.url) {  case '/' :      res.writeHead(200,{"Content-Type": "text/html"})        fs.createReadStream("index.html","UTF-8").pipe(res);    break;

case '/lit-html.js':
var file = fs.readFileSync('lib/lit-html.mjs','UTF-8')
res.writeHead(200,{"Content-Type": "application/javascript"})
res.end(file);

打破;

這是在index.html中

<script type="module" src="localhost:8000/lit-html.js"></script> <script> import {html, render} from 'localhost:8000/lit-html.js';

您的網絡服務器正在嘗試將lit-html.js的網址請求lit-html.js到名為lib/lit-html.mjs的文件

如果您是通過npm安裝的lit-html ,則文件名為lit-html.js ,它將存儲在node_modules/lit-html/lit-html.js

如您所見,兩者不匹配。

檢查擴展名和文件位置

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM