Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Failed to construct transformer: Error: Failed to start watch mode. #1804

Closed
Nantris opened this issue Apr 3, 2020 · 36 comments
Closed

Failed to construct transformer: Error: Failed to start watch mode. #1804

Nantris opened this issue Apr 3, 2020 · 36 comments

Comments

@Nantris
Copy link

Nantris commented Apr 3, 2020

Required format for issues

Please make our job easier by filling this template out to completion.

Description

expo start results in the following error message no matter what I try. Perhaps caused by a failure of expo upgrade? When using expo upgrade we get: \ Updating packages to compatible versions (where known).yarnpkg exited with non-zero code: 1 - so we upgraded everything manually. I'm pretty certain everything is setup correctly.

We tried clearing Haste and Metro caches, and expo start -c, but the outcome is always the same. Also tried removing packagerOpts from our app.json.

Expected Behavior

Development bundle builds properly

Observed Behavior

The following error:

Failed to construct transformer:  Error: Failed to start watch mode.
    at Timeout._onTimeout (C:\projects\myProject\node_modules\jest-haste-map\build\index.js:1059:24)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)
(node:7964) UnhandledPromiseRejectionWarning: Error: Failed to start watch mode.
    at Timeout._onTimeout (C:\projects\myProject\node_modules\jest-haste-map\build\index.js:1059:24)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)
(node:7964) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7964) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Environment

Expo CLI 3.17.11 environment info:
  System:
    OS: Windows 7 6.1.7601 (Using PowerShell)
  Binaries:
    Node: 12.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.21.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.2.0 - C:\Users\MyUser\AppData\Roaming\npm\npm.CMD
  IDEs:
    Android Studio: Version  2.3.0.0 AI-162.3871768
  npmPackages:
    expo: ^37.0.0 => 37.0.3
    react: 16.9.0 => 16.9.0
    react-native: https://github.com/expo/react-native/archive/sdk-37.0.0.tar.gz => 0.61.4

Also specify:

  • Phone/emulator/simulator platform, model and version: Physical Pixel 2, Android 9.x (although things don't get that far)

Reproducible Demo

N/A

@brentvatne
Copy link
Member

try reverting to sdk 36 and running the expo upgrade command on expo-cli@3.17.14 - it will tell you which modules failed to install and you can just do those after the rest of the upgrade is complete and figure out what went wrong

@Nantris
Copy link
Author

Nantris commented Apr 3, 2020

@brentvatne thanks for your response.

Trying to rely on expo upgrade seems not to be an option here. What's the easiest way to confirm the proper expo dependency versions to match 36.0.0, or to otherwise upgrade manually?

This is the output of expo upgrade 36.0.0. Nothing changes in our package.json

x Failed to install expo package with error: yarnpkg exited with non-zero code: 1
√ Installed expo@^36.0.0.
√ Validated configuration.
‼ Please manually delete the sdkVersion field in your project app.config file, it is deprecated.
√ No additional changes necessary to app.json config.
x Failed to upgrade JavaScript devDependencies: babel-preset-expo@^8.0.0
x Failed to upgrade JavaScript dependencies: expo-asset@~6.0.0 expo-constants@~6.0.0 expo-file-system@~6.0.0 expo-font@~6.0.1 expo-haptics@~6.0.0 expo-keep-awake@~6.0.0 expo-secure-store@~6.
0.0 react-native-gesture-handler@~1.3.0 react-native-reanimated@~1.1.0 react-native-screens@1.0.0-alpha.22 react-native-svg@~9.5.1 react-native-webview@~5.12.0 react-native@https://github.co
m/expo/react-native/archive/sdk-36.0.1.tar.gz react@16.9.0
√ Updated known packages to compatible versions.
x Failed to clear packager cache with error: Metro Bundler process exited with code 1
√ Cleared packager cache.

? Automated upgrade steps complete.

No changes appear to have been made to the filesystem in the node_modules folder, nor the yarn.lock file. The only change that seems to have been made is removing sdkVersion from our app.json.

@brentvatne
Copy link
Member

brentvatne commented Apr 3, 2020

there is something wrong with the yarn setup on your machine, it's hard to say but it seems that invoking it via yarnpkg add expo@^36.0.0 does not work. you should symlink yarnpkg to yarn

@brentvatne
Copy link
Member

see this existing issue: #1455

@brentvatne
Copy link
Member

if you can reproduce after fixing that then i'll reopen the issue, let me know!

@Nantris
Copy link
Author

Nantris commented Apr 3, 2020

That doesn't seem to be the issue unfortunately, unless I'm misunderstanding. I assume yarnpkg should be configured as shown below?

> which yarn
> C:\Program Files (x86)\Yarn\bin\yarn.CMD
> which yarnpkg
> C:\Program Files (x86)\Yarn\bin\yarnpkg.CMD

We're using lerna, but never had trouble with Expo's upgrade scripts in the past.

If expo upgrade can't easily be made to work in this setup anymore, how would you advise I go about manually configuring? Specifically how do we know what version of the expo-* packages (like expo-file-system) go with what version of Expo? There's a lot of info on upgrading in the blog posts/linked resources, but I didn't see anything about this bit. Thanks again @brentvatne!

@brentvatne
Copy link
Member

@slapbox - you should be able to run yarnpkg install expo@^36.0.0 in your project directory and have that work. let me know if you run that and it works but expo install and expo upgrade don't work

@Nantris
Copy link
Author

Nantris commented Apr 4, 2020

@brentvatne thanks for the advice. I tried yarnpkg install but since it doesn't exist anymore I used yarnpkg add instead. So I did yarnpkg add expo@36.0.0 and go the following error:

error An unexpected error occurred: "expected workspace package to exist for \"@babel/preset-env\"".

It seems to be related to this yarnpkg/yarn#7807 (comment)

Several solutions are suggested which people seem to have success with. Seems the underlying issue is this: yarnpkg/yarn#7734

I tried deleting my yarn.lock file, and it seemed to work at first, but eventually yielded:

error An unexpected error occurred: "expected workspace package to exist for \"babelify\"".

Trying the next suggested solution: yarn policies set-version 1.18.0 now.

Update: Nope. Using yarn policies didn't seem to do anything for the issue.

@brentvatne
Copy link
Member

brentvatne commented Apr 4, 2020

ooh interesting! so it seems like an issue with using yarn add inside of your workspaces setup maybe?

@Nantris
Copy link
Author

Nantris commented Apr 4, 2020

It does appear to be related to workspaces/monorepo usage, unfortunately. Any thoughts besides trying yarn 1.18.0? (Which I'm trying to find an installer for currently)

@brentvatne
Copy link
Member

not really familiar with debugging this kind of issue. if yarn works then the upgrade command will work though

@Nantris
Copy link
Author

Nantris commented Apr 4, 2020

I figured as much but never hurts to ask for advice. Is there any good reference for what I should do to upgrade manually if it comes to that?

@brentvatne
Copy link
Member

well if you can't run yarn add in your project you won't be able to upgrade at all probably :O maybe you should use npm if yarn isn't working for you? you can pass in the --npm flag

@brentvatne
Copy link
Member

brentvatne commented Apr 4, 2020

another thing - if you can't get yarn working you should still see the packages that it fails to install listed along with the message about it failing. i added this yesterday in response to this thread just in case

eg: in your above message

x Failed to upgrade JavaScript devDependencies: babel-preset-expo@^8.0.0
x Failed to upgrade JavaScript dependencies: expo-asset@~6.0.0 expo-constants@~6.0.0 expo-file-system@~6.0.0 expo-font@~6.0.1 expo-haptics@~6.0.0 expo-keep-awake@~6.0.0 expo-secure-store@~6.
0.0 react-native-gesture-handler@~1.3.0 react-native-reanimated@~1.1.0 react-native-screens@1.0.0-alpha.22 react-native-svg@~9.5.1 react-native-webview@~5.12.0 react-native@https://github.co
m/expo/react-native/archive/sdk-36.0.1.tar.gz react@16.9.0

i'm not sure how you are using yarn if yarn add doesn't work but you could do whatever your equivalent of that is and copy that list of deps over

@Nantris
Copy link
Author

Nantris commented Apr 4, 2020

That's what I would think, but all my experience aligns with one of the comments from that issue:

but manually bumping versions in package.json still works fine for some reason.

expo upgrade 36.0.0 --npm does indeed work, although I suspect this is asking for endless headaches to do this. It is really useful to get the correct versions written to package.json which I should be able to get to install properly with just a plain yarn in the monorepo.

@Nantris
Copy link
Author

Nantris commented Apr 4, 2020

@brentvatne I had thought that was the case but then I noticed that the versions for all the expo-* packages I checked hadn't changed so I figured I was mistaken to make that assumption. It looks like most of those packages just didn't get bumped between SDK 34 and SDK 36 though, so it was a mistake for me to rely on that as an indicator.

I've downgraded yarn to 1.18.0 and I'll let you know how that goes. Otherwise the solution is probably to use the --npm flag to build the package.json as a sort of dry run.

Thanks a lot, I really appreciate your help!

@Nantris
Copy link
Author

Nantris commented Apr 4, 2020

@brentvatne Unfortunately the original issue persists after getting the versions upgraded properly via yarn. Any thoughts on the root cause? Full error text

@Nantris
Copy link
Author

Nantris commented Apr 4, 2020

I reviewed our Babel configuration and made it match the default as closely as possible, having no idea if that's related at all. Unfortunately that didn't make a difference.

@brentvatne
Copy link
Member

can you share a minimal reproducible example? maybe strip out parts from your codebase until the bare minimum is left for this to still happen. my guess based on your issues with yarn is that this another tooling problem and perhaps related to workspaces

@Nantris
Copy link
Author

Nantris commented Apr 5, 2020

@brentvatne I got it halfway fixed. I stupidly didn't ensure that react-native was symlinked properly after running yarn since I went through so many iterations. That fixed the issue, sort of...

Unfortunately it seems like half the time that I start the project I need to manually clear out C:\Users\MyUser\AppData\Local\Temp\metro-cache or the error returns seemingly every few startups.

There's no way to know if the cache is invalid though without waiting 4 minutes for the build process to tell you it can't start watch mode.

So that has me pre-emptively clearing the Metro cache, which means something like 7-8 minutes to start the project, and sooner or later the server stops responding and I need to end it with Ctrl+C and then start the process anew.

Can you let me know exactly what expo start -c clears? Is it the Babel cache? Some other cache I'm not even aware of? All I'm able to be sure of is that the Metro cache isn't included in what's cleared.

A more general question, do you know what affects initial build time so I can try to make this process go faster and reach a firm answer about the cause/solution? Do unused, unreferenced dependencies add to the cache build time simply by existing in the package.json or node_modules/?

Sorry, this got a bit longer than I meant it to be.

@brentvatne
Copy link
Member

expo start -c passes in --reset-cache to react-native-cli when starting metro:

if (options.reset) {
cliOpts.push('--reset-cache');
} // Get custom CLI path from project package.json, but fall back to node_module path
let defaultCliPath = resolveModule('react-native/local-cli/cli.js', projectRoot, exp);

there are lots of factors that impact build time, eg: babel transforms that you use. i think this is a more general question you could ask to the metro team to see if maybe they have some tooling to help you better understand where the time is being spent in cold build of your app

@PaulKish
Copy link

PaulKish commented May 6, 2020

I am experiencing the same issue. My current expo environment is:

Expo CLI 3.20.1 environment info:
System:
OS: Windows 10 10.0.18363
Binaries:
Node: 12.16.3 - C:\Program Files\nodejs\node.EXE
npm: 6.14.4 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.5.0.0 AI-191.8026.42.35.6010548
npmPackages:
expo: ^37.0.0 => 37.0.8
react: 16.9.0 => 16.9.0
react-dom: 16.9.0 => 16.9.0
react-native: https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz => 0.61.4
react-native-web: ^0.11.7 => 0.11.7
react-navigation: ^4.1.1 => 4.3.9

@Nantris
Copy link
Author

Nantris commented May 6, 2020

This issue does indeed persist for me. expo start -c doesn't resolve it, but manually deleting the Metro/haste cache folders does.

I think it's just the Metro cache folder that matters, but I run this command and it works:

cd "\Users\yourUser\AppData\Local\Temp" ; rm -rf ./haste* ; rm -rf ./metro-cache*

@PaulKish
Copy link

I noticed installing Watchman seems to have fixed my issues

@Nantris
Copy link
Author

Nantris commented May 27, 2020

Installing Watchman doesn't make a difference in my case (Windows.)

@manny1001
Copy link

I'm having same issue, I have tried all above recommended solutions, Nothing works, can some one advise me?

@Nantris
Copy link
Author

Nantris commented Sep 25, 2020

@manny1001 environment info? OS/version/Expo CLI version/anything else relevant?

@lylest
Copy link

lylest commented Oct 10, 2020

same shit here

@wpdas
Copy link

wpdas commented Jan 13, 2021

I faced this issue when I first started my project using a specific version of node (10). Later, when I went back to the project to keep developing, I forgot to use the same node version and started to get this issue. Going back to the version that I used to create the project worked for me.

@BismarkCodes
Copy link

run npm install -g expo-cli and restart the development server. This worked for me

@rahuldasgupta
Copy link

had faced the same issue multiple times, this always worked in my case

  1. clear expo cache
  2. restart the system
  3. delete node_modules and reinstall all the packages with npm/yarn

@Dakuan
Copy link

Dakuan commented May 4, 2022

still a thing with a fresh install, none of the above solutions work

@brentvatne
Copy link
Member

@Dakuan - if you are experiencing this, create a new issue and provide as much information as possible to help people understand.

also, if you haven't done so already, try installing watchman: https://facebook.github.io/watchman/

@Dakuan
Copy link

Dakuan commented May 17, 2022

not compatible with latest node was my issue....

@Savic3916
Copy link

This happened to me today while running my app on Expo GO.
All I did was reinstalling node modules using
'npm install'

Since you're using yarn, try
'yarn install'

Restart your project with
npm start or yarn start

And that's all.

@Sumansourabh14
Copy link

For me, simply restarting my system worked.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests