我的导入在我的javascript文件中工作得很好,但是当我启动web服务器时它们不工作。我可以像预期的那样访问导入模块的函数,但是当我启动nodejs服务器时,import语句本身失败了。
我在javascript类的顶部添加了下面的import语句,没有出现错误
import * as Ably from 'ably';
我的HTML文件在body标签的末尾有这个
<script src="./app.js" type="module"></script>
我从inspect元素中得到以下错误(在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>
而不是导入。此外,检查此线程,看起来类似于您的问题未能解决模块