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

loadable-components: Cannot resolve webpack modules with single quotes #300

Closed
sigorilla opened this issue May 13, 2024 · 0 comments · Fixed by #302
Closed

loadable-components: Cannot resolve webpack modules with single quotes #300

sigorilla opened this issue May 13, 2024 · 0 comments · Fixed by #302
Assignees

Comments

@sigorilla
Copy link

Input:

loadable(() => import(/* webpackChunkName: 'ChunkA' */ "./ModA"));

Current output:


loadable({
    resolved: {},
    chunkName () {
        return "'ChunkA'";
    },
    isReady (props) {
        const key = this.resolve(props);
        if (this.resolved[key] !== true) {
            return false;
        }
        if (typeof __webpack_modules__ !== 'undefined') {
            return !!__webpack_modules__[key];
        }
        return false;
    },
    importAsync: ()=>import(/*webpackChunkName: "'ChunkA'"*/ "./ModA"),
    requireAsync (props) {
        const key = this.resolve(props);
        this.resolved[key] = false;
        return this.importAsync(props).then((resolved)=>{
            this.resolved[key] = true;
            return resolved;
        });
    },
    requireSync (props) {
        const id = this.resolve(props);
        if (typeof __webpack_require__ !== 'undefined') {
            return __webpack_require__(id);
        }
        return eval('module.require')(id);
    },
    resolve () {
        if (require.resolveWeak) {
            return require.resolveWeak("./ModA");
        }
        return eval('require.resolve')("./ModA");
    }
});

Expected output:

loadable({
    resolved: {},
    chunkName () {
        return "ChunkA";
    },
    isReady (props) {
        const key = this.resolve(props);
        if (this.resolved[key] !== true) {
            return false;
        }
        if (typeof __webpack_modules__ !== 'undefined') {
            return !!__webpack_modules__[key];
        }
        return false;
    },
    importAsync: ()=>import(/*webpackChunkName: "ChunkA"*/ "./ModA"),
    requireAsync (props) {
        const key = this.resolve(props);
        this.resolved[key] = false;
        return this.importAsync(props).then((resolved)=>{
            this.resolved[key] = true;
            return resolved;
        });
    },
    requireSync (props) {
        const id = this.resolve(props);
        if (typeof __webpack_require__ !== 'undefined') {
            return __webpack_require__(id);
        }
        return eval('module.require')(id);
    },
    resolve () {
        if (require.resolveWeak) {
            return require.resolveWeak("./ModA");
        }
        return eval('require.resolve')("./ModA");
    }
});

Version: @swc/[email protected]

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

Successfully merging a pull request may close this issue.

2 participants