SyntaxError:意外的令牌' export'下划线

发布于 2025-01-23 12:59:52 字数 237 浏览 1 评论 0原文

当我将下划线js复制到控制台时,我会遇到此错误。 错误屏幕截图“ usffact Syntaxerror;意外的令牌'export''

我尝试了两个Chrome版本100.0。 4896.127和Opera LVL3(核心:85.0.4341.72)如果有帮助。

I'm getting this error when I copy-paste the underscore.js to my console. Error screenshot "Uncaught SyntaxError; Unexpected token 'export'"

I tried on both Chrome Version 100.0.4896.127 and Opera LVL3 (core: 85.0.4341.72) if that helps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海夕 2025-01-30 12:59:52

意外的令牌'导出'表示引擎遇到的JavaScript的导出关键字,仅当您进行< script> type = module>时才允许。这意味着您可能将ESM捆绑包复制到控制台(underscore-esm.js),这不是针对这种情况的。

要将拷贝性放入控制台中,UMD捆绑包(underscore-umd.js)更合适。这将为您提供一个全局_变量,使您可以访问所有下划线功能。

在编写JavaScript项目“严重”时,通常会做类似的事情:

import _, { times, debounce } from 'underscore';

如果您使用的是ESM平台(可能需要设置导入映射或类似的 delias Configuration 在某些情况下)或类似的东西:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/underscore-umd-min.js"></script>

如果您将依赖项直接连接到HTML页面。

Unexpected token 'export' means that the engine encountered JavaScript's export keyword, which is only allowed when you do <script type=module>. This means that you probably copied the ESM bundle to your console (underscore-esm.js), which is not meant for this scenario.

For copy-pasting into the console, the UMD bundle (underscore-umd.js) is more suitable. This will give you a global _ variable that lets you access all Underscore functions.

When writing JavaScript projects "for serious", you will generally either do something like this:

import _, { times, debounce } from 'underscore';

if you are using an ESM platform (which may require setting up an import map or similar alias configuration in some cases), or something like this:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/underscore-umd-min.js"></script>

if you are attaching your dependencies directly to an HTML page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文