javascript - 使用 CRA 时如何调整 babel 加载器以正确导入名为 macro.js 的模块
问题描述
我正在使用库 vtk.js。VTK 有一个特殊的类设计(https://kitware.github.io/vtk-js/docs/develop_class.html)。当我编写一个类时,我需要导入 macro.js 模块,该模块公开了几个基本方法,例如 getters/setters/newInstance 等(https://github.com/Kitware/vtk-js/blob/master/Sources/macro.js)。
看起来 CRA 为 macro.js 文件使用了一些特殊的加载器。尝试导入此类文件 ( SyntaxError: Cannot use import statement outside a module
) 时出现错误。如果我将原始文件 macro.js 从 @kitware/vtk.js 复制到我的本地源文件夹,我仍然会收到错误消息。即使我删除了 macro.js 文件的所有内容,我也会收到错误 ( The macro imported from "../macro" must be wrapped in "createMacro" which you can get from "babel-plugin-macros". Please refer to the documentation to see how to do this properly: https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/author.md#writing-a-macro
)。但是,当我将 macro.js 重命名为 macro2.js 时,错误就消失了。
有什么方法可以禁用这个宏加载器吗?
解决方案
推荐阅读
- object - 系列对象没有属性clip_upper
- python - Tkinter:如何将结束索引更改为空格
- javascript - ESLint 对类异步方法的“意外令牌”投诉
- javascript - 在具有 id 和日期的对象数组中嵌套分组?
- c# - 在 Identity Server 4.0.3 中,如何正确授予给定客户端对 ApiResource 的访问权限?
- excel - 为什么 Excel 宏将 - 识别为问号?
- apache-spark - 如何在pyspark中使用带有句点的列的fillna函数
- python - Jupyter Notebook 单元一直在运行(永不停止)
- c++ - 水平平铺包含 QScrollArea 的 QMdiArea 子窗口
- html - 字符串中的 HTML 标签,转换为普通字符串