UstymUkhman / vite-plugin-glsl

:spider_web: Import, inline (and compress) GLSL shader files :electric_plug:
https://www.npmjs.com/package/vite-plugin-glsl
MIT License
321 stars 21 forks source link

Cannot find module 'node:path' #15

Closed ShulkMaster closed 2 years ago

ShulkMaster commented 2 years ago

Hi I'm using this plugin in a newly created project wit svelte and typescript however I'm getting this error:

failed to load config from D:\Documentos\GitHub\piare\vite.config.ts
error when starting dev server:
Error: Cannot find module 'node:path'
Require stack:
- D:\Documentos\GitHub\piare\node_modules\vite\dist\node-cjs\publicUtils.cjs
- D:\Documentos\GitHub\piare\node_modules\vite\index.cjs
- D:\Documentos\GitHub\piare\node_modules\vite-plugin-glsl\dist\index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)

Checking if the is anybody that can help me? 👀

🔗 Link of my repo with issues in case someone wants to test

The project is basically what you get when running:

npm create vite@latest

and filling for svelte and typescript

Node version v14.17.5 in a Windows 10 machine.

I did see #13 another issue with similar conditions ( svelte and node v14.17) however the error is different and already try removing the

"type": "module"

from the packaje json. Also Package.json

"devDependencies": {
    "@sveltejs/vite-plugin-svelte": "^1.0.1",
    "@tsconfig/svelte": "^3.0.0",
    "@types/node": "^18.0.4",
    "svelte": "^3.49.0",
    "svelte-check": "^2.8.0",
    "svelte-preprocess": "^4.10.7",
    "tslib": "^2.4.0",
    "typescript": "^4.6.4",
    "vite": "^3.0.0",
    "vite-plugin-glsl": "^0.2.2"
  }
import { defineConfig } from 'vite'
import glsl from 'vite-plugin-glsl';
import { svelte } from '@sveltejs/vite-plugin-svelte'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [svelte()]
})

event when not adding glsl to the plugin array still show the same issue.

also try to change the tsconfig.json

from

"module": "ESNext",

to

"module": "CommonJS",

but the same issue appears. Sorry for the long text but I tried to provide as much details as possible 😥

UstymUkhman commented 2 years ago

Hi @ShulkMaster and thanks for opening this issue. Unfortunately though, I'm afraid it's not related to this plugin since as you've said:

even when not adding glsl to the plugin array still show the same issue.

I think it's more similar to one of these:

Anyway, I've tested your repo and it works for me (also Windows 10, but node v16.15.1).

If you don't want to upgrade node, I think you can firstly try to rename svelte.config.js to svelte.config.mjs, and then add "moduleResolution": "node" to the compilerOptions in your tsconfig.json. I was facing another error (may be related to yours?) when running yarn dev, but these 2 small updates fixed that.

As described in here, you can use "type": "module" in you package.json, but in that case, you'll also need to update vite.config.ts in this way:

import { defineConfig } from 'vite'
import glsl from 'vite-plugin-glsl';
import { svelte } from '@sveltejs/vite-plugin-svelte'

export default defineConfig({
  plugins: [svelte(), glsl.default()]
});

I hope that helps you. Please let me know if you've had any progress with this and thanks for your ⭐!

Cheers!

ShulkMaster commented 2 years ago

Hi. thank you very much for taking the time and help me. 😊 I really appreciate it.

I was triying to keep the same version of node if possible so I try your suggestions about using svelte.config.mjs and "moduleResolution": "node" as well a a few other tricks but as you point out this it's not related to this plugin. In fact it is an issue whit vite itselft since Vite version 3 uses node: import which is supported in v16.0.0+ and v14.18.0+

I update to node 16+ so now it work fine.

Here is the comment where I found exactly what was happening liana-p coment

In case somebody else has this issue and needs to keep on node 14.x probably they what to stick with node v14.18.0 instead of 16 as I did.

Now I can continue in my journey with svelte and WebGL thank a lot.

UstymUkhman commented 2 years ago

Yeah, exactly. I've also noticed (just a few hours ago) that vite v3.0.0 was release and this is a breaking change. Just wanted to let you know I'm working on a new version to handle this update properly.