javascript - 试图在 ZX 命令行上运行 .mjs 脚本
问题描述
我试图在我的 ubuntu 操作系统上运行这个示例。
https://github.com/google/zx/blob/main/examples/basics.mjs
在我从 npm 安装 zx 之后
通过npm i -g zx
并运行以下命令:
sudo zx ./script.mjs
我得到以下错误:
/usr/local/lib/node_modules/zx/zx.mjs:17
import {basename, dirname, extname, join, parse, resolve} from 'path'
^
SyntaxError: Unexpected token {
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
我的 npm 版本是:7.14.0
解决方案
正如上面的评论所解释的:
该问题源于无法识别该import
功能的旧版本节点。仅从以下版本可用:v13+(请参阅https://stackoverflow.com/questions/39436322/node-js-syntaxerror-unexpected-token-import)
推荐阅读
- java - Java 仅调用以 parent 作为其函数参数的方法
- node.js - 如何将构建文件从一个容器复制到另一个容器或 docker 上的主机
- reactjs - 将 ReactJs 应用程序部署为静态应用程序以在 U 盘上使用
- rust - 在不同集合中存储对相同项目的引用:移动后借用的值
- angular - 在 ngFor 中获取对子组件的引用
- python - 有没有办法在一侧绘制一个带有弧线的 matplotlib 补丁矩形?
- wordpress - Wordpress:未找到作者设置而不是页面
- python - 泛型类的类方法
- javascript - 用 Cypress 不计算 React 站点中的 DOM 元素?
- rust - Rust Crossclip 剪贴板的打印类型