报错util is relative but relative import paths are not supported in module mode
这个错误通常在使用 ES6 模块化的项目中出现,是因为在模块中使用了相对路径来导入模块,而这种方式在模块化中是不支持的。
解决方法是使用绝对路径来导入模块,或者将项目的模块化方式改为 CommonJS 规范。
例如,将相对路径:
import someUtil from './util';
改为绝对路径:
import someUtil from '/src/util';
或者改为 CommonJS 规范的导入方式:
const someUtil = require('./util');
原文地址: https://www.cveoy.top/t/topic/YsZ 著作权归作者所有。请勿转载和采集!