nuxt / bridge

🌉 Experience Nuxt 3 features on existing Nuxt 2 projects
MIT License
273 stars 29 forks source link

ERROR [h3] [unhandled] Expected input to be a string #985

Closed Moxxxem closed 11 months ago

Moxxxem commented 11 months ago

Environment


Reproduction

After installing nuxt bridge and turn on bridge: true in nuxt.config.js, change 'nuxt' to 'nuxi' in package.json, reinstall dependencies run 'npm run dev'.

Describe the bug

After running app, next compiling client and server, after compiling i'm open localhost and have { "statusCode": 500, "stack": [] } on the screen and
ERROR [h3] [unhandled] Expected input to be a string at the console

Additional context

Before compiling nuxt throw ERROR [worker reload] Cannot read properties of null (reading 'address') at console, but after compiling nitro builded correctly

Logs

ERROR  [worker reload] Cannot read properties of null (reading 'address')                                                                                 1:23:38 PM

  at _reload (node_modules/nitropack/dist/shared/nitro.37241ef0.mjs:282:38)
  at runNextTicks (node:internal/process/task_queues:60:5)
  at process.processTimers (node:internal/timers:509:9)
  at async _applyPromised (node_modules/perfect-debounce/dist/index.mjs:54:10)

ℹ Watching ~/assets/icons/ for new icons                                                                                                  @nuxtjs/svg-sprite 13:23:46

 ERROR  [worker reload] Cannot read properties of null (reading 'address')                                                                                 1:23:46 PM

  at _reload (node_modules/nitropack/dist/shared/nitro.37241ef0.mjs:282:38)
  at async _applyPromised (node_modules/perfect-debounce/dist/index.mjs:54:10)

✔ Nitro built in 269 ms                                                                                                                             nitro 1:23:46 PM
ℹ Waiting for file changes                                                                                                                                1:23:46 PM

 ERROR  [h3] [unhandled] Expected input to be a string                                                                                                     1:23:52 PM

  at picomatch.test (node_modules/picomatch/lib/picomatch.js:119:11)
  at matcher (node_modules/picomatch/lib/picomatch.js:67:50)
  at micromatch (node_modules/micromatch/index.js:49:21)
  at matchSingleGlobPath (node_modules/http-proxy-middleware/dist/context-matcher.js:46:21)
  at Object.match (node_modules/http-proxy-middleware/dist/context-matcher.js:15:16)
  at HttpProxyMiddleware.shouldProxy (node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:86:35)
  at HttpProxyMiddleware.<anonymous> (node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:28:22)
  at Generator.next (<anonymous>)
  at node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:8:71
  at new Promise (<anonymous>)
  at __awaiter (node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:4:12)
  at HttpProxyMiddleware.middleware [as handler] (node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:26:47)
  at Object.handler (node_modules/h3/dist/index.mjs:1675:31)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async NuxtDevServer.toNodeHandle [as _handler] (node_modules/nuxi/dist/shared/nuxi.a4b9172a.mjs:648:7)

 ERROR  [h3] [unhandled] Expected input to be a string                                                                                                     1:23:52 PM

  at picomatch.test (node_modules/picomatch/lib/picomatch.js:119:11)
  at matcher (node_modules/picomatch/lib/picomatch.js:67:50)
  at micromatch (node_modules/micromatch/index.js:49:21)
  at matchSingleGlobPath (node_modules/http-proxy-middleware/dist/context-matcher.js:46:21)
  at Object.match (node_modules/http-proxy-middleware/dist/context-matcher.js:15:16)
  at HttpProxyMiddleware.shouldProxy (node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:86:35)
  at HttpProxyMiddleware.<anonymous> (node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:28:22)
  at Generator.next (<anonymous>)
  at node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:8:71
  at new Promise (<anonymous>)
  at __awaiter (node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:4:12)
  at HttpProxyMiddleware.middleware [as handler] (node_modules/http-proxy-middleware/dist/http-proxy-middleware.js:26:47)
  at Object.handler (node_modules/h3/dist/index.mjs:1675:31)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async NuxtDevServer.toNodeHandle [as _handler] (node_modules/nuxi/dist/shared/nuxi.a4b9172a.mjs:648:7)
wattanx commented 11 months ago

This will be resolved in the next patch release of nitro. ref: https://github.com/nuxt/nuxt/issues/24423

Moxxxem commented 11 months ago

This will be resolved in the next patch release of nitro. ref: nuxt/nuxt#24423

Ty for answer, but i have trouble with "Expected input to be a string" error after application compiling (below nitro errors in logs)

wattanx commented 11 months ago

The error 'Expected input to be a string' seems to be caused by a module you are using, not by nuxt/bridge. Can you provide an environment where this can be reproduced? (I couldn't reproduce it with the steps you've written.) https://stackblitz.com/github/nuxt/starter/tree/v2-bridge

Moxxxem commented 11 months ago

Reproduce it with my config & package.json, ty for help: https://stackblitz.com/edit/github-ewdyxk

Moxxxem commented 11 months ago

Solve this problem. Remove @nuxtjs/axios from modules and remove axios and proxy from config.

Removed:

  axios: {
    credentials: true,
    proxy: true
  },
  proxy: {
    '/api/**': {
      target: process.env.API_URL,
      secure: false,
      changeOrigin: true,
      pathRewrite: { '^/api': '' },
      headers: {
        Connection: 'keep-alive'
      }
    }
  },

Added:

nitro: {
    sourceMap: false,
    devProxy: {
      '/api/': {
        target: process.env.API_URL,
        secure: false,
        changeOrigin: true,
        pathRewrite: { '^/api': '' },
        headers: {
          Connection: 'keep-alive'
        }
      }
    }
  }