oklas / react-app-alias

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

Error on Mac and Linux when using classes, while on Windows everything is working fine. #94

Open ptimer opened 1 year ago

ptimer commented 1 year ago

config-overrides.js

const { aliasWebpack } = require('react-app-alias-ex')
const path = require('path');

module.exports = function override(config) {
    aliasWebpack({
        alias: {
            '@commonTypes': path.resolve(__dirname, '../../../some-common-types/')
        }
    })(config);

    return config;
}

some-common-types/firstFile.ts

import { ExampleClass } from '@commonTypes/anotherFile'

export class ExportedClass {
  static create() {
    return new ExampleClass();
  }
}

some-common-types/secondFile.ts

export class ExampleClass {
    name: string;
  }

Let's call it inside a React component.

import { ExportedClass } from '@commonTypes/firstFile'

const SomeComponent = (): JSX.Element => {
ExportedClass.create();
...
}

Error

/home/user/Desktop/project/public/dash/node_modules/react-dev-utils/ModuleScopePlugin.js:32
request.descriptionFileRoot.indexOf('/node_modules/') !== -1 ||
^

TypeError: Cannot read properties of undefined (reading 'indexOf')
at /home/user/Desktop/project/public/dash/node_modules/react-dev-utils/ModuleScopePlugin.js:32:39
at Hook.eval [as callAsync] (eval at create (/home/user/Desktop/project/public/dash/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:52:1)
at Resolver.doResolve (/home/user/Desktop/project/public/dash/node_modules/enhanced-resolve/lib/Resolver.js:432:16)
at /home/user/Desktop/project/public/dash/node_modules/enhanced-resolve/lib/TryNextPlugin.js:32:14
at _next0 (eval at create (/home/user/Desktop/project/public/dash/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:173:1)
at eval (eval at create (/home/user/Desktop/project/public/dash/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:195:1)
at /home/user/Desktop/project/public/dash/node_modules/enhanced-resolve/lib/ConditionalPlugin.js:40:47
at Hook.eval [as callAsync] (eval at create (/home/user/Desktop/project/public/dash/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:187:1)
at Resolver.doResolve (/home/user/Desktop/project/public/dash/node_modules/enhanced-resolve/lib/Resolver.js:432:16)
at /home/user/Desktop/project/public/dash/node_modules/enhanced-resolve/lib/ConditionalPlugin.js:42:14