question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

addServerMiddleware deprecation and replacement with addServerHandler

See original GitHub issue

Environment

Nuxt CLI v3.0.0-rc.3 11:44:59 RootDir: C:\Users\auser\Desktop\adir\anotherdir\examples\nuxt 11:45:01 Nuxt project info: 11:45:01


  • Operating System: Windows_NT
  • Node Version: v18.4.0
  • Nuxt Version: 3.0.0-rc.3
  • Package Manager: yarn@1.22.17
  • Builder: vite
  • User Config: modules, nitro, buildModules, alias, runtimeConfig
  • Runtime Modules: ~/modules/nuxt-mdg
  • Build Modules: nuxt-windicss@^2.2.8

Reproduction

Internal Repo.

Describe the bug

Hello fellow nuxt 3 team!

Initially, I’ve created a module which uses a token middleware. This middleware was used with the current deprecated function addServerMiddleware as:

addServerMiddleware(join(__dirname, "server/middleware/token.ts")

After the deprecation of the method and the replacement of it with addServerHandler, the nuxt project would not start up giving me the following error:

ERROR [worker reload] [worker init] Unable to find global scope. Are you sure this is running in the browser?

and by removing the addServerMiddleware functionality everything worked as before (Without the token) So I replaced it with the newer addServerHandler(handler) as below:

addServerHandler({ route: "/token", middleware:true, handler: join(__dirname, "server/middleware/token.ts"), })

but the new error I getting was :

ERROR [worker reload] [worker init] Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol ‘c:’

Doing some searching I found out that many people mentioned it is a node version issue but that’s not the case since I am using the latest version.

Is it possible to have a working example of addServerHandler?

Thank you in advance nuxt team and @danielroe !!

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
abarkecommented, Jul 25, 2022

Thanks for your reply @danielroe seems the problem is fixed now. I managed to upgrade to 3.0.0-rc.6 and fixed the code. The error does not appear anymore after initial tests 🎉

1reaction
danielroecommented, Jul 26, 2022

The reason we’re using a string is that we want to keep build config (e.g. nuxt.config) separate from actual runtime code. Functions within nuxt config can’t be safely serialised to something we want to run/include in the nitro rollup build.

👍 And yes, it would be good to add a comment in JSdoc pointing to the h3 docs/helper function for defining such a handler: http://v3.nuxtjs.org/guide/features/server-routes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deprecations by version - GitLab Docs
The maintainer_note argument in the POST /runners REST endpoint was deprecated in GitLab 14.8 and replaced with the maintenance_note argument.
Read more >
3.0.0-rc.8 - Renovate Bot Package Diff
+ * @deprecated Please use `addImports` instead with nuxt>=3.0.0-rc.9 ... addPlugin, addPluginTemplate, addServerHandler, addServerMiddleware, addTemplate, ...
Read more >
On the reaction to deprecation of clients of 4 + 1 popular Java ...
API developers often deprecate features, and when replace them with new ones, changes can break the client's code. Studies such as.
Read more >
Last issues related to nuxt/framework project - PullAnswer
More obvious deprecation of Nuxt 2 settings in `nuxt.config.js`. 5 Likes 3 Replies ... addServerMiddleware deprecation and replacement with addServerHandler.
Read more >
Azure SDK for Python (Deprecated)
You can also find migration guidance and replacement package information in the entry on the package manager. The new Azure SDK libraries are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found