oklas / react-app-alias

:label: Alias and multiple src directory for craco or rewired create-react-app
MIT License
173 stars 18 forks source link

alias(configPath()) is not working with baseUrl = src #69

Closed oklas closed 2 years ago

oklas commented 2 years ago

Originally posted by @MassMessage in https://github.com/oklas/react-app-rewire-alias/issues/2

this is not working for me:

module.exports = function override(config)
{
    return alias(configPaths('./tsconfig.paths.json'))(config);
}

I get the error:

[0] Module not found: Can't resolve '@Shared/ChannelName' in 'C:\Users\jckj33\Desktop\merge\Newton\src\components'

but this is working:

module.exports = function override(config)
{
    config.resolve = config.resolve || {};
    config.resolve.alias = config.resolve.alias || {};

    Object.assign(config.resolve.alias, {
        '@Shared': path.resolve(__dirname, 'src/shared')
    });

    return config
};

tsconfig.paths.json is defined like this:

{
    "compilerOptions":
    {
        "baseUrl": "src",
        "paths": {
            "@Shared/*": ["shared/*"]
        }
    }
}

What am I missing?

I just found out alias(configPaths()) isn't considering the baseUrl in tsconfig.paths.jsona file when generating the paths so give the paths in the orginal poster, it is generating:

    alias: {
      'react-native': 'react-native-web',
       '@Shared': 'C:\\Users\\jckj33\\Desktop\\merge\\Newton\\shared'
     }

instead of:

    alias: {
       'react-native': 'react-native-web',
       '@Shared': 'C:\\Users\\jckj33\\Desktop\\merge\\Newton\\src\\shared'
     }

note it's missing the src folder as defined in the baseUrl in the tsconfig.paths.json file. Any workaround for this to keep using alias(configPaths())

Originally posted by @MassMessage in https://github.com/oklas/react-app-rewire-alias/issues/2

MassMessage commented 2 years ago

Are there any workaround for this issue? is this considered a bug?

oklas commented 2 years ago

Thank you for full description. Yesterday I spent some time on this question, I hope there will be more time and information today.

oklas commented 2 years ago

This is actually a duplicate of #10, so let us move there. I will add a reference to this issue to avoid missing of some details.

oklas commented 2 years ago

Released in react-app-alias-v2.2.0 :tada:. Check for Using baseUrl section in readme. Feel free to reopen or create new if any. Thanks.