我正在尝试将本地自定义 Nuxt 模块添加到我的 Nuxt 应用程序中,但我不断收到错误消息:
Cannot read property 'startsWith' of undefined
at Resolver.g [as _require] (node_modules\jiti\dist\jiti.js:1:54052)
at Resolver.requireModule (node_modules\@nuxt\core\dist\core.js:381:29)
at ModuleContainer.addModule (node_modules\@nuxt\core\dist\core.js:182:38)
at node_modules\@nuxt\utils\dist\utils.js:639:43
at async ModuleContainer.ready (node_modules\@nuxt\core\dist\core.js:55:5)
at async Nuxt._init (node_modules\@nuxt\core\dist\core.js:478:5)
我在 Nuxt 模块的 module.js 中需要如下所示的“路径”:
const { resolve, join } = require('path')
const { readdirSync } = require('fs')
它显示具有startsWith() 的文件列表。例如:
node_modules@nuxt\utils\dist\utils.js:
const startsWithAlias = aliasArray => str => aliasArray.some(c => str.startsWith(c));
...
const isWindows = process.platform.startsWith('win');
...
if (r.path && r.path.startsWith('/')) {
routes.push(r.path);
} else if (route !== '/' && route[route.length - 1] === '/') {
routes.push(route.slice(0, -1));
} else {
routes.push(route);
}
...
const sanitizedKey = key.startsWith('_') ? key.substr(1) : key;
...
if (key.startsWith('_') && key.length > 1) {
route.path += '?';
}
...
if (
dir1 &&
dir2 &&
(
dir1 === dir2 ||
(
dir1.startsWith(dir2) &&
!path__default['default'].basename(dir1).startsWith(path__default['default'].basename(dir2))
)
)
) {
...
if (key.startsWith('_')) {
return `:${key.substr(1)}`
}