vite-plugin-solid icon indicating copy to clipboard operation
vite-plugin-solid copied to clipboard

Warning: "deps.registerNodeLoader" is deprecated

Open jtmueller opened this issue 10 months ago • 8 comments

When running vitest 0.34.2, if I have vite-plugin-solid registered as a plugin, the following warning is logged:

Vitest "deps.registerNodeLoader" is deprecated. If you rely on aliases inside external packages, use "deps.optimizer.web.include" instead.

If I remove vite-plugin-solid from the vitest config, no warnings are logged.

jtmueller avatar Aug 23 '23 06:08 jtmueller

Same with me. Another weird thing that I cannot figure out for the life of me @jtmueller is that when I have the vite-plugin-solid plugin enabled in my vite config, my tests all are duplicated (they each run twice)!! Have you noticed this at all? It is driving me insane, haha. See here: https://github.com/solidjs/vite-plugin-solid/issues/112#issuecomment-1698476208

GitMurf avatar Aug 30 '23 04:08 GitMurf

You can remove the warning by using optimizer and server config:

  test: {
    server: {
      deps: {
        // fixes: You appear to have multiple instances of Solid. This can lead to unexpected behavior.
        inline: [/solid-js/],
      },
    },
    deps: {
      // fixes: Vitest "deps.registerNodeLoader" is deprecated. If you rely on aliases inside external packages, use "deps.optimizer.web.include" instead.
      optimizer: {
        web: {
          enabled: true,
        },
      },
    },
  }

https://github.com/vitest-dev/vitest/releases/tag/v0.34.0 From release notes:

Deprecate deps.registerNodeLoader - by @sheremet-va (7f45b) This option was introduced to support aliasing inside external packages. Please, use deps.optimizer.web instead. If you test Node.js applications, consider adding external packages to server.deps.inline.

alarivan avatar Aug 31 '23 17:08 alarivan

@alarivan Thanks, that gets rid of the warning for me - I was logging the issue mostly so that the next version of vite-plugin-solid wouldn't trigger the deprecation warning by default, but I appreciate the workaround.

@GitMurf I was seeing the deprecation warning twice, but at least after applying the above workaround, the actual tests don't seem to run more than once.

jtmueller avatar Sep 11 '23 22:09 jtmueller

@GitMurf I was seeing the deprecation warning twice, but at least after applying the above workaround, the actual tests don't seem to run more than once.

When I am running my unit tests with vitest, whenever I use my main vite config that has the vite-plugin-solid included, it runs my tests twice!

FYI see this thread for the solution to my additi issue mentioned above: https://github.com/solidjs/vite-plugin-solid/pull/101#issuecomment-1698495511

GitMurf avatar Sep 12 '23 07:09 GitMurf

Why is that not working for me?

  • vitest 0.34.6
  • vite 4.5.0
  • vite-plugin-solid 2.7.2 My vitest.config.ts Снимок экрана 2023-11-20 в 11 51 04

And I get this Снимок экрана 2023-11-20 в 11 53 40

Tur8008 avatar Nov 20 '23 08:11 Tur8008

@Tur8008 I was also unable to suppress the deprecation message using the above recommendations.

This message seems to be caused by the SolidPlugin()'s returned config-patch object that contains the deprecated property:

https://github.com/solidjs/vite-plugin-solid/blob/7e667ad0bb05ba55e0a4a3e185ecc7e3e3535e4f/src/index.ts#L338

I was able to develop a workaround that patches-out the deprecated property (setting it to undefined) which effectively suppresses the deprecation message when running vitest:

[email protected] [email protected] [email protected].

- import { defineConfig } from "vitest/config";
+ import { type UserConfig, defineConfig } from "vitest/config";
import SolidPlugin from "vite-plugin-solid";

export default defineConfig({
  // ...
  plugins: [
-    SolidPlugin(),
+    // @workaround
+    // `"deps.registerNodeLoader" is deprecated.`
+    (() => {
+      const plugin = SolidPlugin();
+      const { config } = plugin;
+      return Object.assign(plugin, {
+        config: async (...args: any[]) => {
+          const result: UserConfig = await (config as any)(...args);
+          if (result.test?.deps?.registerNodeLoader) {
+            result.test.deps.registerNodeLoader = undefined;
+          }
+          return result;
+        },
+      });
+    })(),
  ],
  // ...
});

I'm not sure whether or not this patched-out property will cause any other problems -- but for now it seems okay!

[edit 1] ~Sorry, it seems to completely crash vite dev with TypeError: Cannot read properties of undefined (reading 'deps') -- I'll have to look into it further.~

[edit 2] Turns out I made a mistake in the original version of my workaround diff causing a config error if not running in the "test" mode. I've fixed my code snippet to first check for the property before attempting to clear it.

peterboyer avatar Nov 30 '23 07:11 peterboyer

Works also with [email protected], [email protected] and [email protected] Yepp! Just have updated site-plugin-solid up to 2.9.1 and problem has gone. Thank you! They fixed that, at last.

Tur8008 avatar Jan 28 '24 20:01 Tur8008