How to use the @nuxt/utils.clearRequireCache function in @nuxt/utils

To help you get started, we’ve selected a few @nuxt/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nuxt / nuxt.js / packages / core / src / resolver.js View on Github external
let lastError

    // Try to resolve path
    try {
      resolvedPath = this.resolvePath(path, { isAlias })
    } catch (e) {
      lastError = e
    }

    const isExternal = isExternalDependency(resolvedPath)

    // in dev mode make sure to clear the require cache so after
    // a dev server restart any changed file is reloaded
    if (this.options.dev && !isExternal) {
      clearRequireCache(resolvedPath)
    }

    // By default use esm only for js,mjs files outside of node_modules
    if (useESM === undefined) {
      useESM = !isExternal && /.(js|mjs)$/.test(resolvedPath)
    }

    // Try to require
    try {
      if (useESM) {
        requiredModule = this.esm(resolvedPath)
      } else {
        requiredModule = require(resolvedPath)
      }
    } catch (e) {
      lastError = e
github nuxt / nuxt.js / packages / cli / src / utils / config.js View on Github external
let nuxtConfigFile
  let options = {}

  try {
    nuxtConfigFile = require.resolve(path.resolve(rootDir, argv['config-file']))
  } catch (e) {
    if (e.code !== 'MODULE_NOT_FOUND') {
      throw (e)
    } else if (argv['config-file'] !== defaultNuxtConfigFile) {
      consola.fatal('Could not load config file: ' + argv['config-file'])
    }
  }

  if (nuxtConfigFile) {
    // Clear cache
    clearRequireCache(nuxtConfigFile)

    options = esm(module)(nuxtConfigFile) || {}

    if (options.default) {
      options = options.default
    }

    if (typeof options === 'function') {
      try {
        options = await options()
        if (options.default) {
          options = options.default
        }
      } catch (error) {
        consola.error(error)
        consola.fatal('Error while fetching async configuration')
github nuxt / nuxt.js / packages / builder / src / builder.js View on Github external
async (event, fileName) => {
        if (['add', 'change', 'unlink'].includes(event) === false) {
          return
        }
        /* istanbul ignore if */
        if (serverMiddlewarePaths.includes(fileName)) {
          consola.debug(`Clear cache for ${fileName}`)
          clearRequireCache(fileName)
        }
        await this.nuxt.callHook('watch:fileChanged', this, fileName) // Legacy
        await this.nuxt.callHook('watch:restart', { event, path: fileName })
      },
      this.assignWatcher('restart')