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

jest-haste-map: Haste module naming collision: react-native #26397

Closed
ldco2016 opened this issue Sep 10, 2019 · 9 comments
Closed

jest-haste-map: Haste module naming collision: react-native #26397

ldco2016 opened this issue Sep 10, 2019 · 9 comments
Labels
Bug Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@ldco2016
Copy link

When I run a local script to build an .ipa I consistently get the following error in Metro Packager console:

jest-haste-map: Haste module naming collision: react-native
  The following files share their name; please adjust your hasteImpl:
    * <rootDir>/node_modules/react-native/package.json
    * <rootDir>/ios/build/Archive/DEV.xcarchive/Products/Applications/DEV.app/assets/node_modules/react-native/package.json

I have tried doing an rm -rf ios/build but I continue to get the above error.

React Native version:

System:
    OS: macOS High Sierra 10.13.6
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
    Memory: 105.17 MB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 10.16.3 - /usr/local/bin/node
    Yarn: 1.10.1 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
    Watchman: 4.7.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
    Android SDK:
      API Levels: 23, 25, 26, 27, 28
      Build Tools: 23.0.1, 26.0.2, 27.0.3, 28.0.3
      System Images: android-28 | Google Play Intel x86 Atom
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 10.1/10B61 - /usr/bin/xcodebuild
  npmPackages:
    @react-native-community/cli: 2.9.0 => 2.9.0
    react: 16.8.6 => 16.8.6
    react-native: 0.60.4 => 0.60.4
  npmGlobalPackages:
    react-native-cli: 2.0.1
    react-native-git-upgrade: 0.2.7

Steps To Reproduce

  1. download: https://www.dropbox.com/s/9ic96cz9qupi97j/ipa_release_2.0.zip?dl=0
  2. run npm install
  3. go to node_modules:

node_modules/react-native-immediate-phone-call/android/build.gradle AND
node_modules/react-native-swipe-view/android/build.gradle

change compileSdkVersion to 28

change targetSdkVersion to 27

  1. Run npx jetify && npm run build
  2. It will prompt you for codesigning password, just give it the password to get into your machine.

Describe what you expected to happen:

The script executed with npm run build should successfully create an apk that gets stored inside of Dist/ folder, but the .ipa is not generated because of the above error.

https://www.dropbox.com/s/9ic96cz9qupi97j/ipa_release_2.0.zip?dl=0

@ldco2016 ldco2016 added the Bug label Sep 10, 2019
@Frindecent
Copy link

you might be importing package.json in your js code. Remove that import and then try to start your bundler again.

@ldco2016
Copy link
Author

@Frindecent , I have found that package.json is being required in 521 files, but I will guess I should remove it from the scripts that is attempting to generate the apks and ipas.

@Frindecent
Copy link

Frindecent commented Sep 10, 2019

You donot need to remove package.json from the dependencies or packages.. lets say ‘react-native-vector-icons’.
Just remove the import of package.json from the original code you wrote for your app. You might be importing it for app version or maybe app name

@ldco2016
Copy link
Author

@Frindecent , the only place where I saw in our own code that package.json is being imported is:

e2e/init.js:

const detox = require("detox");
// const config = require("../package.json").detox;
// importing package.json ^^^
const adapter = require("detox/runners/jest/adapter");

jest.setTimeout(120000);
jasmine.getEnv().addReporter(adapter);

beforeAll(async () => {
  await detox.init(config);
});

beforeEach(async () => {
  await adapter.beforeEach();
});

afterAll(async () => {
  await adapter.afterAll();
  await detox.cleanup();
});

scripts/ios/build.js:

import path from "path";
import { execSync } from "child_process";
import { name, iosDirectory } from "../../app.json";
// import { version } from "../../package.json";
// importing package.json ^^^
import { resolveFromRoot, distDir, createLogger } from "../build";

const getProcessOptions = () => {
  return {
    env: Object.assign({}, process.env, {
      // used to skip packager, since we default to release bundler is built in
      RCT_NO_LAUNCH_PACKAGER: true,
      CI_IOS_VERSION_NAME: version
      // CI_IOS_BUILD_NUMBER: build,
    })
  };
};

scripts/build.js:

import yargs from "yargs";
import path from "path";
import fs from "fs-extra";
import { version } from "../package.json";

export const buildArgv = yargs.options({
  version: { string: true, default: version }
  // build: { number: true, demandOption: 'build number must be passed' },
});

export const resolveFromRoot = (pathStr: string) =>
  path.resolve(__dirname, `../${pathStr}`);
export const distDir = resolveFromRoot("dist");

const makeDirIfNotExists = dir => {
  if (!fs.existsSync(dir)) {
    fs.mkdirSync(dir);
  }
};

I could not comment it out from the last one because it would error out.

Results:

Still getting in Metro Packager:

jest-haste-map: Haste module naming collision: react-native
  The following files share their name; please adjust your hasteImpl:
    * <rootDir>/node_modules/react-native/package.json
    * <rootDir>/ios/build/Build/Intermediates.noindex/ArchiveIntermediates/DEV/InstallationBuildProductsLocation/Applications/DEV.app/assets/node_modules/react-native/package.json

@Frindecent
Copy link

You will need to comment it out from the last one too.. check what is the version in package.json.. and then after commenting write

Const version = “whatever the version is” . So you wont have errors.. and next time while changing the version of the app you will change from here too

@ldco2016
Copy link
Author

ldco2016 commented Sep 11, 2019

@Frindecent , I did the following refactor to scripts/build.js:

import yargs from "yargs";
import path from "path";
import fs from "fs-extra";
// import { version } from "../package.json";
const version = "4.0.0";

export const buildArgv = yargs.options({
  version: { string: true, default: version }
  // build: { number: true, demandOption: 'build number must be passed' },
});

export const resolveFromRoot = (pathStr: string) =>
  path.resolve(__dirname, `../${pathStr}`);
export const distDir = resolveFromRoot("dist");

const makeDirIfNotExists = dir => {
  if (!fs.existsSync(dir)) {
    fs.mkdirSync(dir);
  }
};

export const makeFolderPath = dirPath => {
  const pathParts = dirPath.split("/").reduce((acc, curr) => {
    const newPath = path.join(acc, curr);
    makeDirIfNotExists(newPath);
    return newPath;
  }, resolveFromRoot("."));
};

const repeatString = (input, length) => {
  return Array.from({ length })
    .map(_ => input)
    .join("");
};

export const createSectionHeader = (
  input,
  { repeatChar = "*", maxLen = 80 } = {}
) => {
  if (input.length >= maxLen) {
    return input;
  }
  // added 2 for spaces around input
  const paddingNeeded = maxLen - (input.length + 2);
  const padding = repeatString(repeatChar, Math.floor(paddingNeeded / 2));
  return [padding, input, padding].join(" ");
};

// todo: make this better, pass logType and curry
export const logAndWriteLine = (logger, input) => {
  console.log(input);
  logger.write(`${input}\n`);
};

export const createLogger = args => {
  let id = args;
  if (typeof id === "object") {
    id = args.id;
  }
  makeFolderPath("./dist/log");
  const buildLogPath = resolveFromRoot(`dist/log/build-${id}.log`);
  // use same file name and delete before opening stream
  if (fs.existsSync(buildLogPath)) {
    fs.removeSync(buildLogPath);
  }
  const stream = fs.createWriteStream(buildLogPath);

  return {
    logHeader: (input, { repeatChar, maxLen } = {}) => {
      const header = createSectionHeader(input, { repeatChar, maxLen });
      console.log(header);
      // error below
      stream.write(`${header}\n`);
    },

    write: input => stream.write(input),
    log: input => console.log(input),
    error: input => {
      stream.write(input.message ? input.message : input);
      console.error(input);
    },
    close: () => stream.close()
  };
};

I still get the following error when running npm run android:

jest-haste-map: Haste module naming collision: react-native
  The following files share their name; please adjust your hasteImpl:
    * <rootDir>/node_modules/react-native/package.json
    * <rootDir>/ios/build/Archive/DEV.xcarchive/Products/Applications/DEV.app/assets/node_modules/react-native/package.json

Failed to construct transformer:  { Error: Duplicated files or mocks. Please check the console for more info
    at setModule (/Users/danale/Projects/NFIBEngage/node_modules/jest-haste-map/build/index.js:620:17)
    at workerReply (/Users/danale/Projects/NFIBEngage/node_modules/jest-haste-map/build/index.js:691:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  mockPath1: 'node_modules/react-native/package.json',
  mockPath2:
   'ios/build/Archive/DEV.xcarchive/Products/Applications/DEV.app/assets/node_modules/react-native/package.json' }
error Duplicated files or mocks. Please check the console for more info. Run CLI with --verbose flag for more details.
Error: Duplicated files or mocks. Please check the console for more info
    at setModule (/Users/danale/Projects/NFIBEngage/node_modules/jest-haste-map/build/index.js:620:17)
    at workerReply (/Users/danale/Projects/NFIBEngage/node_modules/jest-haste-map/build/index.js:691:9)
    at process._tickCallback (internal/process/next_tick.js:68:7)

The only way I am able to get the scripts working is by running:

rm -rf ios/build && GitVersion_BranchName="release/abcd" npm run build, so I have to remove ios/build directory first.

To be clear this does not resolve it, it eventually creates the /ios/build/Archive/DEV.xcarchive/Products/Applications/DEV.app/assets/node_modules/react-native/package.json this all over again.

@ldco2016
Copy link
Author

The way I had to resolve this was by first running rm /ios/build/Archive/DEV.xcarchive/Products/Applications/DEV.app/assets/node_modules/react-native/package.json

@stale
Copy link

stale bot commented Dec 16, 2019

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 16, 2019
@stale
Copy link

stale bot commented Dec 23, 2019

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Dec 23, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Dec 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

2 participants