diff --git a/packages/react-scripts/config/modules.js b/packages/react-scripts/config/modules.js index 22820993a25..1488d089f3d 100644 --- a/packages/react-scripts/config/modules.js +++ b/packages/react-scripts/config/modules.js @@ -36,7 +36,10 @@ function getAdditionalModulePaths(options = {}) { // Allow the user set the `baseUrl` to `appSrc`. if (path.relative(paths.appSrc, baseUrlResolved) === '') { - return [paths.appSrc]; + return { + resolved: [paths.appSrc], + relative: [baseUrl], + }; } // If the path is equal to the root directory we ignore it here. diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index e465d8e7a00..e90be53ba3a 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -308,7 +308,9 @@ module.exports = function (webpackEnv) { // if there are any conflicts. This matches Node resolution mechanism. // https://github.com/facebook/create-react-app/issues/253 modules: ['node_modules', paths.appNodeModules].concat( - modules.additionalModulePaths || [] + modules.additionalModulePaths + ? modules.additionalModulePaths.resolved + : [] ), // These are the reasonable defaults supported by the Node ecosystem. // We also include JSX as a common component filename extension to support diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index ff1c5811025..963e7830476 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -8,6 +8,7 @@ 'use strict'; const fs = require('fs'); +const path = require('path'); const chalk = require('react-dev-utils/chalk'); const paths = require('../../config/paths'); const modules = require('../../config/modules'); @@ -52,7 +53,13 @@ module.exports = (resolve, rootDir, isEjecting) => { '[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$', '^.+\\.module\\.(css|sass|scss)$', ], - modulePaths: modules.additionalModulePaths || [], + modulePaths: modules.additionalModulePaths + ? modules.additionalModulePaths.relative.map( + // Absolute paths will cause issues if the ejected jest config is applied on other + // machines, so we translate them to relative paths to the rootDir + modulePath => path.join('', modulePath) + ) + : [], moduleNameMapper: { '^react-native$': 'react-native-web', '^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',