Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Relative assets paths resolve to the node_modules folder #15

Open
markjlorenz opened this issue Jan 23, 2022 · 3 comments
Open

Relative assets paths resolve to the node_modules folder #15

markjlorenz opened this issue Jan 23, 2022 · 3 comments

Comments

@markjlorenz
Copy link

markjlorenz commented Jan 23, 2022

I'm getting the following error

[ERROR] 19:16:15 Error: ENOENT: no such file or directory, open '/app/node_modules/@geckos.io/phaser-on-nodejs/assets/tiles/map.json'
Error: ENOENT: no such file or directory, open '/app/node_modules/@geckos.io/phaser-on-nodejs/assets/tiles/map.json'

My code looks like this:

// src/scenes/Preloader.js
import Phaser from 'phaser';

export default class Preloader extends Phaser.Scene {
    constructor() {
        super("preloader")
    }

    preload() {
        this.load.tilemapTiledJSON("map", "../assets/tiles/map.json")
    }

    create() {
        this.scene.start("game")
    }
}

The full (correct) file path for the the asset is:

/app/src/assets/tiles/map.json

I tried calling this.load.setPath() at the top of Preloader.js#preload, thinking that I might just be able to reset the relative path, but that didn't have any effect.

I see the test for this behavior, but I wonder if it's passing because it also runs in the @geckos.io file path.

I'm using Phaser 3.52.0
`

@markjlorenz
Copy link
Author

markjlorenz commented Jan 23, 2022

I found a workaround using __dirname:

import path from "path"

this.load.tilemapTiledJSON("map", path.join(__dirname, "../assets/tiles/map.json"))

@FedeJure
Copy link

Im facing the same issue but In my case is not that simple. I need to load an asset pack, but due I cannot use the setUrl or setPath is not working :S. there is any chance to have this solved? ty!

@zewa666
Copy link

zewa666 commented Sep 26, 2022

try setting this.load.setBaseUrl instead. Here's an example that redirects it for use with unit tests
https://github.com/zewa666/phaser-vitest-bug/blob/master/src/scenes/Game.ts#L9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants