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

How to isolate node_modules? #423

Open
avlonder opened this issue Feb 7, 2021 · 1 comment
Open

How to isolate node_modules? #423

avlonder opened this issue Feb 7, 2021 · 1 comment

Comments

@avlonder
Copy link

avlonder commented Feb 7, 2021

How do I avoid applying the path mapping to the files inside node_modules?
If, by coincidence, you pick an alias that resembles one of the imports used inside a third-party package, this can lead to unexpected behavior.
I would like to constrain the path mapping only to the files inside src.

@guikubivan
Copy link

guikubivan commented Apr 30, 2024

This would be really helpful and would save me from having to rename all my references in my code.
For others looking for temporary solution, you could try this:

const {resolvePath} = require('babel-plugin-module-resolver');

module.exports = function (api) {
    return {
        plugins: [['module-resolver', {
                    alias: {...},
                    resolvePath(sourcePath, currentFile, opts) {
                        if (currentFile.indexOf(/node_modules/) > -1) {
                            return undefined;
                        }

                        return resolvePath(sourcePath, currentFile, opts);
                    }
        }]]
    };
};

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

2 participants