Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Unable to import glsl file properly #37

Closed
sophyem opened this issue Mar 24, 2023 · 5 comments
Closed

Unable to import glsl file properly #37

sophyem opened this issue Mar 24, 2023 · 5 comments
Assignees
Labels
not an issue Something that doesn't need to be fixed question A question about functionality

Comments

@sophyem
Copy link

sophyem commented Mar 24, 2023

Hi, I am working on a simple three.js project. I am trying to build and import a custom shader into my js code. However, after I installed the vite-plugin-vlsl following every step in the README.md file, I still could not get my js to read the glsl file properly and got the error as following:
Uncaught SyntaxError: Unexpected token '{' (at vertex.glsl?t=1679695882090&import:1:13)

I have restarted the server many times and also tried to tweak the code in the package.json file and vite.config.js file following the discussion in #1

Because the error I keep getting is the same error you would get when you don't have the plugin installed, I checked many times to make sure the setup is correct in every file, but I am still lost at what I am missing here. Thank you for your help in advance!

My package.json file:

{
  "name": "skin-earth",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  },
  "devDependencies": {
    "vite": "^4.2.0",
    "vite-plugin-glsl": "^1.1.2",
    "vite-plugin-string": "^1.2.1"
  },
  "dependencies": {
    "three": "^0.150.1"
  }
}

vite.config.js file

import glsl from 'vite-plugin-glsl';
import { defineConfig } from 'vite';


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

my vertex.glsl file

void main() {
    gl_Position = vec4([1, 0, 0, 1]);
}

my main.js file

import './style.css'
import * as THREE from 'three'
import vertexShader from './shader/vertex.glsl'

console.log(vertexShader)
@sophyem
Copy link
Author

sophyem commented Mar 24, 2023

Happy to report that I just got rid of this error by:

Deleting the node_modules folder and package_lock.json and running npm install again.

@sophyem sophyem changed the title Unable to use the plugin to import glsl file Unable to import glsl file properly Mar 24, 2023
@UstymUkhman
Copy link
Owner

@sophyem Cool! Also, please note that with "type": "module" in your package.json, you don't need to use glsl.default() to set up this plugin in your vite.config, it should work with glsl() only. 😉

@UstymUkhman UstymUkhman self-assigned this Mar 25, 2023
@UstymUkhman UstymUkhman added not an issue Something that doesn't need to be fixed question A question about functionality labels Mar 25, 2023
@sophyem
Copy link
Author

sophyem commented Mar 27, 2023

Thank you for catching that! I changed it

@sophyem
Copy link
Author

sophyem commented Mar 27, 2023

Hi there, Bad news... the error reappeared. Reinstalling didn't actually solve it. Please help!

@UstymUkhman
Copy link
Owner

Hi @sophyem! Sure. This error: Uncaught SyntaxError: Unexpected token '{' (at vertex.glsl?t=1679695882090&import:1:13) is probably due to this line:

gl_Position = vec4([1, 0, 0, 1]);

which should be:

gl_Position = vec4(1, 0, 0, 1);

If changing that still won't work, please try to remove vite-plugin-string 'cause it may conflict with vite-plugin-glsl, and if that won't work, share some repo where I can reproduce this issue. Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
not an issue Something that doesn't need to be fixed question A question about functionality
Projects
None yet
Development

No branches or pull requests

2 participants