hiposfer / hive

Your go-to routing app for public transport
GNU Lesser General Public License v3.0
10 stars 0 forks source link

React Native packager error: Cannot find entry file #105

Closed carocad closed 6 years ago

carocad commented 6 years ago

@mehdisadeghi this is the problem that you have reported to me several times

It seems that this is a general problem due to the sourcemaps in Clojurescript. After some discussions in the #cljsrn channel in slack I got a patch that fixes it. I will talk with the metro packager developers to see if we can get it upstream.

For the time being, we would have to do this manually. I guess a git patch would be better but no time right now :)

This is the error that we get in the terminal

10:59:42 [exp] NotFoundError: Cannot find entry file target/expo/reagent/impl/template.js.js in any of the roots: ["/Users/Camilo/Proyectos/hive"]
10:59:42 [exp]     at DependencyGraph.getAbsolutePath (/Users/Camilo/Proyectos/hive/node_modules/metro/src/node-haste/DependencyGraph.js:316:11)
10:59:42 [exp]     at /Users/Camilo/Proyectos/hive/node_modules/metro/src/DeltaBundler/DeltaCalculator.js:280:416
10:59:42 [exp]     at Generator.next (<anonymous>)
10:59:42 [exp]     at step (/Users/Camilo/Proyectos/hive/node_modules/metro/src/DeltaBundler/DeltaCalculator.js:11:445)
10:59:42 [exp]     at /Users/Camilo/Proyectos/hive/node_modules/metro/src/DeltaBundler/DeltaCalculator.js:11:605
10:59:42 [exp]     at <anonymous>
10:59:42 [exp]     at process._tickCallback (internal/process/next_tick.js:188:7)

It comes from this file: /Users/Camilo/Proyectos/hive/node_modules/metro/src/Server/index.js in the _getOptionsFromUrl function.

It seems that they assumed that the files would always have custom extensions like main.bundle and main.delta. However, the Closure compiler provides the complete filename directly, without any need for further processing which causes the error as an extra .js is appended anyway.

The solution is quite simple. If the entryFile endswith .js then dont append anything, otherwise append a .js. The code changes for that are these:

// Backwards compatibility. Options used to be as added as '.' to the
    // entry module name. We can safely remove these options.
    let entryFile =
    pathname.
    replace(/^\//, '').
    split('.').
    filter(part => {
      if (part === 'map') {
        isMap = true;
        return false;
      }
      if (
      part === 'includeRequire' ||
      part === 'runModule' ||
      part === 'bundle' ||
      part === 'delta' ||
      part === 'assets')
      {
        return false;
      }
      return true;
    }).
    join('.');

    entryFile = entryFile.endsWith('.js') ? entryFile : entryFile + '.js' ;
carocad commented 6 years ago

It seems that this behavior is intended by the metro bundler: https://facebook.github.io/metro/docs/en/getting-started.html#url-and-bundle-request

mehdisadeghi commented 6 years ago

It seems that this behavior is intended by the metro bundler

Does it mean your fix is not going into metro?

btw, here is a patch that can be applied this way:

$ patch node_modules/metro/src/Server/index.js metro.patch
--- index.js    2018-06-27 00:36:07.226552711 +0200
+++ node_modules/metro/src/Server/index.js  2018-06-27 00:37:03.010362163 +0200
@@ -775,7 +775,7 @@

     // Backwards compatibility. Options used to be as added as '.' to the
     // entry module name. We can safely remove these options.
-    const entryFile =
+    let entryFile =
     pathname.
     replace(/^\//, '').
     split('.').
@@ -795,7 +795,8 @@
       }
       return true;
     }).
-    join('.') + '.js';
+    join('.');
+    entryFile = entryFile.endsWith('.js') ? entryFile : entryFile + '.js';

     // try to get the platform from the url
     const platform =
@@ -906,4 +907,4 @@
   }
 }

-module.exports = Server;
\ No newline at end of file
+module.exports = Server;

Moreover applying the patch works like charm on Linux and Mac. No more errors in terminal. On Mac I get that db/unique error in Chrome console which I think is not related to this issue.

carocad commented 6 years ago

btw, here is a patch that can be applied this way:

oh nice. I will add it to the build process so that it goes smoother

Does it mean your fix is not going into metro?

After some further discussions in the #cljsrn channel it seems that this error does not consistently happens for the latest version of the build scripts. Unfortunately we are not there yet so I dont know if this is an isolated problem or a general one. I am waiting for some feedback to see if a PR makes sense.

mehdisadeghi commented 6 years ago

@carocad is this still a problm for us?

carocad commented 6 years ago

@mehdisadeghi to be honest I dont know

since I use my patched version of the packager I never looked back and see if the problem was still there.

Apparently nobody else is having this problem since there doesnt seem to be any reports in the re-natal repo.

I would leave this open for the time being.

I am planning to migrate the project to node.js target which (AFAIK) doesnt have this problem. I think then we can close this properly :)