Home > OS >  GLB File (Uncaught Error: Module parse failed: Unexpected character)
GLB File (Uncaught Error: Module parse failed: Unexpected character)

Time:12-19

I tried to make rails and threejs communicate, everything works well but i have an error on importing a GLB file (model) inside my js file

import modelGlb from '../models/model1.glb'

gltfLoader.load(
    `${modelGlb}`,
    (gltf) => {
        gltf.scene.scale.set(0.3, 0.3, 0.3)
        gltf.scene.position.set(0, 10, 0)
        gltf.scene.rotation.y = Math.PI * 0.5
        scene.add(gltf.scene)

        updateAllMaterials()
        // gui.add(gltf.scene.rotation, 'y', -Math.PI, Math.PI, 0.001).name("rotation")
    }
)

error:

Uncaught Error: Module parse failed: Unexpected character '�' (1:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

Thanks for help

I tried to add glb file on static assets and add an additional_paths but nothing work

  additional_paths: ['app/javascript/models/']

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

  # Extract and emit a css file
  extract_css: false

  static_assets_extensions:
    - .jpg
    - .jpeg
    - .png
    - .gif
    - .tiff
    - .ico
    - .svg
    - .eot
    - .otf
    - .ttf
    - .woff
    - .woff2
    - .glb

  extensions:
    - .mjs
    - .js
    - .sass
    - .scss
    - .css
    - .module.sass
    - .module.scss
    - .module.css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg
    - .glb

I need a simple solution as possible :)

CodePudding user response:

I solved the problem, it was at additional_paths, just need 2**

additional_paths: ['app/javascript/models/**']

  • Related