solidjs / vite-plugin-solid

A simple integration to run solid-js with vite
440 stars 51 forks source link

Warning: "deps.registerNodeLoader" is deprecated #114

Open jtmueller opened 1 year ago

jtmueller commented 1 year ago

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.

GitMurf commented 1 year ago

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

alarivan commented 1 year ago

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.

jtmueller commented 1 year ago

@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.

GitMurf commented 1 year ago

@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

Tur8008 commented 12 months ago

Why is that not working for me?

And I get this

Снимок экрана 2023-11-20 в 11 53 40
peterboyer commented 11 months ago

@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:

vite@4.5.0 vitest@0.34.6 vite-plugin-solid@2.7.2.

- 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.

floratmin commented 10 months ago

Works also with vitest@1.2.1, vite@5.0.11 and vite-plugin-solid@2.8.2

Tur8008 commented 9 months ago

Works also with vitest@1.2.1, vite@5.0.11 and vite-plugin-solid@2.8.2 Yepp! Just have updated site-plugin-solid up to 2.9.1 and problem has gone. Thank you! They fixed that, at last.