SyntaxError:意外的令牌' export'下划线
当我将下划线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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
意外的令牌'导出'
表示引擎遇到的JavaScript的导出
关键字,仅当您进行< script> type = module>
时才允许。这意味着您可能将ESM捆绑包复制到控制台(underscore-esm.js
),这不是针对这种情况的。要将拷贝性放入控制台中,UMD捆绑包(
underscore-umd.js
)更合适。这将为您提供一个全局_
变量,使您可以访问所有下划线功能。在编写JavaScript项目“严重”时,通常会做类似的事情:
如果您使用的是ESM平台(可能需要设置导入映射或类似的 delias Configuration 在某些情况下)或类似的东西:
如果您将依赖项直接连接到HTML页面。
Unexpected token 'export'
means that the engine encountered JavaScript'sexport
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:
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:
if you are attaching your dependencies directly to an HTML page.