create-react-native-app icon indicating copy to clipboard operation
create-react-native-app copied to clipboard

Failed building JavaScript bundle error when application starts

Open nb256 opened this issue 9 years ago • 12 comments

Description

When I first create a create-react-native-app project and scan qr on my phone with expo, It threw javascipt bundling error instead of starting.

Expected Behavior

I expect to see my lovely first working react-native application

Observed Behavior

333333333333333

222222222222222222222

11:21:59: Failed building JavaScript bundle
11:21:59: Error: Expected path `C:\Users\Naim\Documents\projects\nativedeneme\node_modules\metro-bundler\src\Resolver\polyfills\prelude_dev.js` to be relative to one of the project roots
11:21:59:     at toLocalPath (C:\Users\Naim\Documents\projects\nativedeneme\node_modules\metro-bundler\src\node-haste\lib\toLocalPath.js:33:9)
11:21:59:     at ModuleCache.createPolyfill (C:\Users\Naim\Documents\projects\nativedeneme\node_modules\metro-bundler\src\node-haste\ModuleCache.js:166:18)
11:21:59:     at DependencyGraph.createPolyfill (C:\Users\Naim\Documents\projects\nativedeneme\node_modules\metro-bundler\src\node-haste\DependencyGraph.js:312:30)
11:21:59:     at map.moduleName (C:\Users\Naim\Documents\projects\nativedeneme\node_modules\metro-bundler\src\Resolver\index.js:150:38)
11:21:59:     at Array.map (native)
11:21:59:     at Resolver.getModuleSystemDependencies (C:\Users\Naim\Documents\projects\nativedeneme\node_modules\metro-bundler\src\Resolver\index.js:150:5)
11:21:59:     at _resolverPromise.then.resolver (C:\Users\Naim\Documents\projects\nativedeneme\node_modules\metro-bundler\src\Bundler\index.js:273:31)
11:21:59:     at <anonymous>
11:21:59:     at process._tickCallback (internal/process/next_tick.js:188:7)

Environment

  • npm ls react-native-scripts: [email protected]
  • npm ls react-native: [email protected]
  • npm ls expo: [email protected]
  • node -v: v8.2.1
  • npm -v: 4.6.1
  • yarn --version: 'yarn' is not recognized as an internal or external command
  • watchman version: Please specify a target and action
  1. Operating system: Windows 10 Pro 1703
  2. Phone/emulator/simulator & version: Galaxy J7 (2016) SM-J710FQ Android 7.0 (Expo 1.20.0) (Nexus_5X_API_25_2 Android 7.1.1 and Nexus_5X_API_23 Android 6.0 emulators in Android Studio gave same error)

Reproducible Demo

npm install -g create-react-native-app create-react-native-app nativedeneme cd nativedeneme npm start Scan QR code with Expo on the phone

node_modules\metro-bundler\src\node-haste\lib\toLocalPath.js: (this dude is unhappy I think)

'use strict';var _require =

require('path');const relative = _require.relative;

// FIXME: This function has the shortcoming of potentially returning identical
// paths for two files in different roots.
function toLocalPath(
roots,
absolutePath)
{
  for (let i = 0; i < roots.length; i++) {
    const localPath = relative(roots[i], absolutePath);
    if (localPath[0] !== '.') {
      return localPath;
    }
  }

  throw new Error(
  `Expected path \`${absolutePath}\` to be relative to one of the project roots`);

}

module.exports = toLocalPath;

Installing yarn and using it instead of npm for everything gave same error.

nb256 avatar Oct 10 '17 08:10 nb256

Hi! It looks like this bug in metro-bundler was recently resolved, and we should have support for it soon.

c.f. https://github.com/facebook/metro-bundler/pull/54

anp avatar Oct 17 '17 19:10 anp

@dikaiosune I have seen that commit and tried changing toLocalPath.js file by myself last week. It doesn't quite work for me. Am I missing something? Should I eject first or do another else instead of manually changing lines on node_modules?

Still same error message after importing basename and adding || basename(absolutePath) == localPath to the condition

maybe my problem is related about something else.

nb256 avatar Oct 18 '17 07:10 nb256

//throw new Error( //Expected path \${absolutePath}` to be relative to one of the project roots`);

Ignoring these lines like this fixed my issue, I think they are not necessary for me right now 😄

edit: DO NOT USE THIS, JUST UPDATE YOUR EXPO APP AND CREATE CREATE-REACT-NATIVE-APP TO C://

nb256 avatar Oct 18 '17 11:10 nb256

i have same problemes how to fix it ?

CaReS0107 avatar Nov 13 '17 17:11 CaReS0107

I am also seeing the same issue. Any quick work around?

jalil avatar Nov 17 '17 04:11 jalil

@CaReS0107 @jalil I solved it by disabling lines that throw error but I don't think this is the right solution. Maybe it helps.

node_modules\metro-bundler\src\node-haste\lib\toLocalPath.js

delete or turn these lines to comments

throw new Error( Expected path \${absolutePath}` to be relative to one of the project roots`);

edit: I realized creating create-react-native-app project to the root folder of my computer solved the issue. I also updated expo app on my phone

cd / create-react-native-app deneme cd deneme yarn start

nb256 avatar Nov 17 '17 08:11 nb256

Getting same error, create-react-native-app to C:\Users\<myUsername> solved the issue. But still, i want to use create-react-native-app on different folder :(

bondansebastian avatar Jan 17 '18 14:01 bondansebastian

@bondansebastian try checking letters' cases in your project path, they should be proper.

In my situation I accidentally used 'cd projects' instead of 'cd Projects', it works for getting in there but it makes something crash :)

nb256 avatar Jan 17 '18 14:01 nb256

i only stop the bundle with ctrl+c (on windows) and again start the project, npm start and the app works fine without errors

ajolote-656 avatar Feb 15 '18 16:02 ajolote-656

in this case, you have to just install >

npm i metro-bundler

in app direcorty https://www.npmjs.com/package/metro-bundler

AkshayDigheGithub avatar Apr 01 '18 15:04 AkshayDigheGithub

Have got 2 similar solutions

  1. delete the node_modules folder then run npm install or
  2. copy out your source code with the project structure intact into a new directory without the node_modules folder then run npm install

this should work

Idimma avatar Jun 27 '18 12:06 Idimma

Hi everyone! It looks like there are a few different issues reported here, and since the original issue is closed, I'm going to ask that new comments on this issue be reported as new issues if they have a new problem or previous fixes aren't working. Thanks!

anp avatar Jun 27 '18 17:06 anp