0

I try to import a js class and use its inner function. When I do this my page won't load due to an unknown error in the import line (when I remove the line page gets loaded).

The class:

export default class BombsMap {
    constructor (block) {
        this.block = block;
    }

    get bombsPlacing() {
        // irrelevant code
        return this.block;
    }

    static nearBombUpdate(rnd_i, rnd_j) {
        // irrelevant code
    }
}

The code from file2:

import BombsMap from './BombsMap';
const inst = new BombsMap(block);

I've tried to import only the function, to change the link to './BombsMap.js', and to import BombsMap with brackets such as { BombsMap }. None of these worked.

1
  • Are you running this script from a server or a local server? What kind of error are you having? If you have a CORS error, it's due to ES6 modules are subject to same-origin policy, and you should run your code into a server or disable the same-origin in the browser Commented Apr 28, 2020 at 11:31

1 Answer 1

1

Check, really your file (immediately file, because in path you put path to file, not a function) named BombsMap in import:

import BombsMap from './BombsMap';
Sign up to request clarification or add additional context in comments.

1 Comment

The file I want to import to called 'app.js', the export file indeed named 'BombsMap.js'. The line you purposed is the code I try to import with, which doesn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.