Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt bridge migration: Cannot start nuxt: Cannot read properties of undefined (reading 'hook') #23551

Closed
jasonsrogers opened this issue Oct 6, 2023 · 5 comments

Comments

@jasonsrogers
Copy link

Environment

System:
OS: macOS 13.5.1
CPU: (10) arm64 Apple M2 Pro
Memory: 61.47 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.5.1 - /usr/local/bin/node
npm: 9.8.0 - /usr/local/bin/npm
Browsers:
Brave Browser: 117.1.58.129
Safari: 16.6

Reproduction

Create a new project

npm init nuxt-app nuxt-basic

With the following prompt answers:

create-nuxt-app v5.0.0
✨  Generating Nuxt.js project in nuxt-basic
? Project name: nuxt-basic
? Programming language: TypeScript
? Package manager: Npm
? UI framework: Bootstrap Vue
? Template engine: HTML
? Nuxt.js modules: (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Linting tools: (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Testing framework: Jest
? Rendering mode: Single Page App
? Deployment target: Static (Static/Jamstack hosting)
? Development tools: (Press <space> to select, <a> to toggle all, <i> to invert selection)jsconfig.json (Recommended for VS Code if you're not using typescript), Semantic Pull Requests, Dependabot (For auto-updating dependencies, GitHub only)
? Continuous integration: None
? What is your GitHub username? jason
? Version control system: Git

Follow migration guide

When you reach step to switch to nuxi I get:

Cannot restart nuxt: Cannot read properties of undefined (reading 'hook')

My package.json:

{
  "name": "nuxt-basic",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "nuxi dev",
    "build": "nuxi build",
    "start": "nuxi start",
    "generate": "nuxi generate",
    "test": "jest"
  },
  "dependencies": {
    "bootstrap": "^4.6.2",
    "bootstrap-vue": "^2.22.0",
    "core-js": "^3.25.3",
    "nuxt": "^2.17.1",
    "vue": "^2.7.10",
    "vue-server-renderer": "^2.7.10",
    "vue-template-compiler": "^2.7.10"
  },
  "devDependencies": {
    "@nuxt/bridge": "npm:@nuxt/bridge-edge@^3.0.0-rc.1-28271265.8fa71e1",
    "@nuxt/types": "^2.15.8",
    "@nuxt/typescript-build": "^2.1.0",
    "@vue/test-utils": "^1.3.0",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "^29.1.2",
    "jest": "^29.1.2",
    "jest-environment-jsdom": "^29.1.2",
    "nuxi": "^3.9.0",
    "ts-jest": "^29.0.3",
    "vue-jest": "^3.0.4"
  }
}

my nuxt.config.js:

import { defineNuxtConfig } from "@nuxt/bridge";

export default defineNuxtConfig({
  bridge: {
    typescript: true,
    meta: true,
    nitro: true,
  },
  // Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
  ssr: false,

  // Target: https://go.nuxtjs.dev/config-target
  target: "static",

  // Global page headers: https://go.nuxtjs.dev/config-head
  app: {
    head: {
      title: "nuxt-basic",
      htmlAttrs: {
        lang: "en",
      },
      meta: [
        { charset: "utf-8" },
        { name: "viewport", content: "width=device-width, initial-scale=1" },
        { hid: "description", name: "description", content: "" },
        { name: "format-detection", content: "telephone=no" },
      ],
      link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
    },
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    // https://go.nuxtjs.dev/typescript
    // "@nuxt/typescript-build",
  ],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    // https://go.nuxtjs.dev/bootstrap
    "bootstrap-vue/nuxt",
  ],

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {},
});

Describe the bug

When trying to migrate by adding bridge and switching to nuxi, I get stuck with the following error:

 ERROR  Cannot restart nuxt:  Cannot read properties of undefined (reading 'hook')                                  12:04:49 PM

  at NuxtDevServer._load (node_modules/nuxi/dist/chunks/dev2.mjs:228:31)
  at async NuxtDevServer.load (node_modules/nuxi/dist/chunks/dev2.mjs:187:7)
  at async _applyPromised (node_modules/nuxi/dist/chunks/dev2.mjs:107:10)

ℹ Module meta took 0.35ms to setup.                                                                                12:04:49 PM
ℹ Module nuxt-bridge took 1.52ms to setup.                                                                         12:04:49 PM
ℹ Module imports took 0.39ms to setup.  

Additional context

I'm trying to migrate a bigger project and kept hitting the same error:

Cannot restart nuxt: Cannot read properties of undefined (reading 'hook')

I decided to create a blank project migrate it to 2.17 with bridge and nuxi, and hit the same problem

Logs

No response

@Enola-guy
Copy link

same issue over here, we are stuck in our migration.

 ERROR  Cannot start nuxt:  Cannot read properties of undefined (reading 'hook')                                                                          4:34:00 PM

  at NuxtDevServer._load (node_modules/nuxi/dist/chunks/dev2.mjs:228:31)
const kit = await loadKit(this.options.cwd);
this._currentNuxt = await kit.loadNuxt(...)

this._currentNuxt.hooks is null

@melvinprindustry
Copy link

melvinprindustry commented Oct 13, 2023

Same issue here! Trying to migrate a project with nuxt/bridge. With bridge: true and nuxt2 in the package.json scripts it works fine. But when I try nitro with nuxi I get the same error.

 ERROR  Cannot start nuxt:  Cannot read properties of undefined (reading 'hook')                                10:23:01 AM

  at NuxtDevServer._load (node_modules/nuxi/dist/chunks/dev2.mjs:228:31)
  at async NuxtDevServer.load (node_modules/nuxi/dist/chunks/dev2.mjs:187:7)
  at async NuxtDevServer.init (node_modules/nuxi/dist/chunks/dev2.mjs:182:5)
  at async Object.run (node_modules/nuxi/dist/chunks/dev-child.mjs:103:5)
  at async runCommand$1 (node_modules/nuxi/dist/shared/nuxi.9d864d83.mjs:1647:7)
  at async runCommand$1 (node_modules/nuxi/dist/shared/nuxi.9d864d83.mjs:1638:11)
  at async runMain$1 (node_modules/nuxi/dist/shared/nuxi.9d864d83.mjs:1770:7)

Because of the recency of this issue I tried downgrading to 3.8.4 and this issue does not appear on this version of nuxi.

@danielroe
Copy link
Member

This should be resolved once Nuxt Kit v3.8 is released (#23502).

@jasonsrogers
Copy link
Author

@danielroe thanks for the update

any idea when this will be released (just to know roughly when to check again)?

It's been merged 2 weeks ago but it's still 3.7.4 on npmjs

@danielroe
Copy link
Member

danielroe commented Oct 19, 2023

Check later today 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants