簡體   English   中英

ES6 導入語句在 web 服務器上不起作用

[英]ES6 import statements not working on web server

我的導入在我的 javascript 文件中工作正常,但當我啟動網絡服務器時它們不起作用。 我可以按預期訪問導入模塊的功能,但是當我啟動 nodejs 服務器時導入語句本身失敗。

我在 javascript class 的頂部沒有錯誤地添加了以下導入語句

import * as Ably from 'ably';

我的 HTML 文件在 body 標簽的末尾有這個

<script src="./app.js" type="module"></script>

我從檢查元素中得到以下錯誤(vscode 中沒有錯誤)

Uncaught TypeError: Failed to resolve module specifier "ably". Relative references must start with either "/", "./", or "../".

我嘗試更改文件路徑

import * as Ably from './node_modules/ably/ably.js';

但這給了我 404 錯誤

GET http://localhost:3000/node_modules/ably/ably.js net::ERR_ABORTED 404 (Not Found)

嘗試在 HTML 文件中使用<script src="https://cdn.ably.com/lib/ably.min-1.js"></script>而不是導入。 另外,檢查這個線程,看起來類似於你的問題Failed to resolve module

暫無
暫無

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

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