首页 > 解决方案 > 使用 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 时,错误就消失了。

有什么方法可以禁用这个宏加载器吗?

标签: javascriptbabeljscreate-react-appbabel-loadervtk.js

解决方案


推荐阅读