node.js - D3 7.0.0 SyntaxError:意外的令牌“导出”
问题描述
我正在尝试将d3导入我的节点应用程序,但出现以下错误:
$ node src/main.js
this is logged from main.js 2021-07-20 2:33 PM
/Users/michaelosofsky/Developer/shh/node_modules/d3/src/index.js:1
export * from "d3-array";
^^^^^^
SyntaxError: Unexpected token 'export'
at Module._compile (internal/modules/cjs/loader.js:892:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/Users/michaelosofsky/Developer/shh/src/main.js:3:10)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
我尝试按照如何在 Node.js 中正确使用 D3 中描述的导入 d3 的方法?:
yarn add d3
(将 7.0.0 添加到我的 package.json 中)- 放入
var d3 = require("d3");
我的 main.js - 跑
node src/main.js
这似乎正是https://stackoverflow.com/a/9949301/2848676等答案中指定的内容。
如何解决此错误?
解决方案
我发现我可以通过降级我正在使用的 d3 版本来解决这个问题:
yarn remove d3
yarn add d3@4.12.2
node src/main.js
现在它不再给我那个错误了。
我不太了解节点模块约定的细微差别来解释它,但我确实看到了与模块有关的 d3 7.0.0 的变化,所以这可能与根本原因有关:https://github。 com/d3/d3/issues/3501。
推荐阅读
- ios - 在后台上下文中保存 NSManagedObjects 的问题
- java - 当堆使用量达到 80% 时发出通知
- javascript - Javascript:在 ES6 简写中修改嵌套对象
- javascript - 在 PHP 中更新图像的问题
- c# - 如何修复 Selenium 中的“无法滚动到视图中”错误?
- ubuntu - Lubuntu 上没有显示网络接口
- c# - 使用 C# Windows 窗体在 Visual Studio 中创建新页面
- reactjs - 为什么 create-react-app 需要 root 帐户来创建项目
- c++ - 为什么 g++ 会生成巨大的错误日志?
- ios - 如何在 IOS 12 中用新收到的通知(包含相同的通知 ID)替换推送通知