Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
Cannot read property 'startsWith' of undefined require('path') resolve

I am trying to add my local custom Nuxt module to my Nuxt application and I keep getting the error:

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)

I require 'path' as below in module.js of my Nuxt module:

const { resolve, join } = require('path')
const { readdirSync } = require('fs')

It displays a list of files that has startsWith(). For instance:

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)}`
  }
 

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Looks like it might be trying to initialise the module on the client so it's not recognising node specific code.

If by chance you're using the nuxt-vite package for nuxt 2, this could potentially be why as I don't think vite-plugin-vue2 which it uses works with SSR yet.

* I understand that may be a weird mix of vague and specific, but going off the question it looks very similar to an issue my teammate had when looking into nuxt-vite. Also, judging by the stack trace it's failing before it even properly gets in to the module.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!