Invalid depfile: Flutter
Asked Answered
P

27

63

I am following a tutorial from a udemy course and recently I built a new pc so the hard drive that stored my code is secondary right now. When I compile the code, it gives me the following error. To explain it better, I am posting a picture of one warning in my code but I am pretty sure it is an error flutter is making as it usually does with imports. Error in Code I have tried running a test app by making a default app from cmd and that works fine. So obviously, flutter doctor shows no error. the error is repetitive and long so I am pasting some of it below.

The error-

Invalid depfile: D:\WorkSpace\Code\Flutter\Image App\image_app\.dart_tool\flutter_build\8f0d0eee9ef614ed024ca7691a333af8\kernel_snapshot.d
Invalid depfile: D:\WorkSpace\Code\Flutter\Image App\image_app\.dart_tool\flutter_build\8f0d0eee9ef614ed024ca7691a333af8\kernel_snapshot.d

Compiler message:
Error: Could not resolve the package 'http' in 'package:http/http.dart'.
lib/src/app.dart:5:8: Error: Expected ';' after this.
import 'widgets/image_list.dart;'
       ^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/src/app.dart:2:8: Error: Not found: 'package:http/http.dart'
import 'package:http/http.dart' show get; //Only need get so we only care about one Get fuction
       ^
lib/src/app.dart:5:8: Error: Error when reading 'lib/src/widgets/image_list.dart;': The system cannot find the file specified.

import 'widgets/image_list.dart;'
       ^
/C:/src/flutter/packages/flutter/lib/src/material/bottom_navigation_bar.dart:9:8: Error: Error when reading '/C:/Users/dluck/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/vector_math_64.dart': The system cannot find the path specified.

import 'package:vector_math/vector_math_64.dart' show Vector3;
       ^
/C:/src/flutter/packages/flutter/lib/widgets.dart:15:1: Error: Error when reading '/C:/Users/dluck/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/vector_math_64.dart': The system cannot find the path specified.

export 'package:vector_math/vector_math_64.dart' show Matrix4;
^
/C:/src/flutter/packages/flutter/lib/rendering.dart:31:1: Error: Error when reading '/C:/Users/dluck/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/vector_math_64.dart': The system cannot find the path specified.

export 'package:vector_math/vector_math_64.dart' show Matrix4;
^
/C:/src/flutter/packages/flutter/lib/src/widgets/implicit_animations.dart:8:8: Error: Error when reading '/C:/Users/dluck/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/vector_math_64.dart': The system cannot find the path specified.

import 'package:vector_math/vector_math_64.dart';
       ^
/C:/src/flutter/packages/flutter/lib/src/widgets/transitions.dart:8:8: Error: Error when reading '/C:/Users/dluck/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/vector_math_64.dart': The system cannot find the path specified.

import 'package:vector_math/vector_math_64.dart' show Matrix4;
       ^
/C:/src/flutter/packages/flutter/lib/src/widgets/widget_inspector.dart:27:8: Error: Error when reading '/C:/Users/dluck/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/vector_math_64.dart': The system cannot find the path specified.

import 'package:vector_math/vector_math_64.dart';
       ^
/C:/src/flutter/packages/flutter/lib/foundation.dart:12:1: Error: Error when reading '/C:/Users/dluck/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/meta-1.1.8/lib/meta.dart': The system cannot find the path specified.

C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:90:4: Error: Getter not found: 'mustCallSuper'.
  @mustCallSuper
   ^^^^^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:90:4: Error: This can't be used as metadata; metadata should be a reference to a compile-time constant variable, or a call to a constant constructor.
  @mustCallSuper
   ^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:104:4: Error: Getter not found: 'mustCallSuper'.
  @mustCallSuper
   ^^^^^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:104:4: Error: This can't be used as metadata; metadata should be a reference to a compile-time constant variable, or a call to a constant constructor.
  @mustCallSuper
   ^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:118:4: Error: Getter not found: 'protected'.
  @protected
   ^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:118:4: Error: This can't be used as metadata; metadata should be a reference to a compile-time constant variable, or a call to a constant constructor.
  @protected
   ^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:119:4: Error: Getter not found: 'mustCallSuper'.
  @mustCallSuper
   ^^^^^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:119:4: Error: This can't be used as metadata; metadata should be a reference to a compile-time constant variable, or a call to a constant constructor.
  @mustCallSuper
   ^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:139:4: Error: Getter not found: 'protected'.
  @protected
   ^^^^^^^^^

C:/src/flutter/packages/flutter/lib/src/semantics/semantics.dart:3970:4: Error: This can't be used as metadata; metadata should be a reference to a compile-time constant variable, or a call to a constant constructor.
  @required TextDirection thisTextDirection,
   ^
/C:/src/flutter/packages/flutter/lib/src/semantics/semantics.dart:3971:4: Error: Getter not found: 'required'.
  @required TextDirection otherTextDirection,
   ^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/semantics/semantics.dart:3971:4: Error: This can't be used as metadata; metadata should be a reference to a compile-time constant variable, or a call to a constant constructor.
  @required TextDirection otherTextDirection,
   ^
U
nhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:
package%3Ahttp%2Fhttp.dart; message=StandardFileSystem only supports file:* and data:* URIs)
#0      StandardFi
leSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:33:7)
#1      asFileU
ri (package:vm/kernel_front_end.dart:604:37)
#
2      writeDepfile (package:vm/kernel_front
_end.dart:799:21)
<asynchronous suspension>
#
3      FrontendCompiler.compile (package:fron
tend_server/frontend_server.dart:472:15)
<asynchronous 
suspension>
#4      _FlutterFrontendCompiler.comp
ile (package:flutter_frontend_server/server.dar
t:38:22)
#5      starter (package:flutter_fronte
nd_server/server.dart:149:27)
#6      main (f
ile:///C:/b/s/w/ir/cache/builder/src/flutter/fl
utter_frontend_server/bin/starter.dart:8:30)
#7    
  _startIsolate.<anonymous closure> (dart:isol
ate-patch/isolate_patch.dart:305:32)
#8      _RawRec
eivePortImpl._handleMessage (dart:isolate-patch
/isolate_patch.dart:174:12)

Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
build failed.

FAILURE: Build failed with an exception.

* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 780

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 6s
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
Peipeiffer answered 26/3, 2020 at 17:20 Comment(1)
Did you try the command "flutter pub get" ? Because it looks like one of your packages is not found.Ecumenical
P
6

Okay so I found out since I changed the PC, I needed to change permissions of a file. Follow here https://github.com/simolus3/moor/issues/224

Peipeiffer answered 28/3, 2020 at 9:54 Comment(0)
P
64

Sometimes it happens to me too. I either deleted the converted code or converted it command For example here I entered:

import 'dart:html';

, And my error was fixed after deleting it or turning it into a comment

// import 'dart:html';
Pinnace answered 18/1, 2021 at 6:19 Comment(4)
works like charm, why the html make this error?T
In my case, I need to remove import 'dart:js';Gon
Thats horrible, I checked my code and accidently I also imported dart:html, after deleting unnecessary import its solved. thank youFaustinafaustine
Hmm, how do I identify which import is affected? I neither have any "dart:html" nor "dart:js" imports.Commove
O
49

I got the same error and I am following a udemy course as well.
I tried flutter pub get and it worked.

Orth answered 9/8, 2020 at 6:41 Comment(0)
S
20

i also faced the same problem and i sort out by running "flutter clean" command. https://github.com/flutter/flutter/issues/21053

Semicolon answered 10/8, 2020 at 15:51 Comment(0)
B
11

you need clean the project run "flutter Clean" in the project and later run the project normal

Brandi answered 3/9, 2020 at 17:2 Comment(0)
G
11
Invalid depfile: D:\...\f5\.dart_tool\flutter_build\8e234dd4da26339b660f6097cc2a271a\kernel_snapshot.d

Delete kernel_snapshot.d and kernel_snapshot.stamp files at this location:

your flutter project\.dart_tool\flutter_build\8e234dd4da26339b660f6097cc2a271a
Guthrun answered 9/2, 2021 at 18:30 Comment(1)
This worked for me but I still want to know the reason behind this.Unstick
M
9

I face similar problem I solved it by deleting import 'dart:html'; from top of the dart file. i.e remove import 'dart:html';

Meliorate answered 17/3, 2022 at 8:28 Comment(0)
U
7

I have the same bug and I deactivated vs code. When I reactivated it, I just typed

flutter clean

flutter pub get 

flutter run

And everything started to work.

Uredium answered 23/5, 2022 at 13:49 Comment(0)
P
6

Okay so I found out since I changed the PC, I needed to change permissions of a file. Follow here https://github.com/simolus3/moor/issues/224

Peipeiffer answered 28/3, 2020 at 9:54 Comment(0)
O
6

well, you can do two steps to fix this issue

1. flutter clean
2. flutter pub get

after running these commands it should fix your issue

Okeechobee answered 8/3, 2022 at 16:39 Comment(0)
J
5

While you are writing the code, this library is import by itself. ( import 'dart:html';)This causes some problems. You can delete it from the code

Jackquelin answered 18/4, 2023 at 16:16 Comment(3)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Negrillo
check again please and till meJackquelin
Thanks. In my case, it is this file that was imported which was causing the error: import 'dart:js_interop'; I removed it and everything was fine.Moeller
P
4

Like many of you have suggested, I tried out almost all the things mentioned here and several other StackOverflow posts. But nothing worked for me.

The build error I got:

Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
Running Xcode build...
Xcode build done.                                           17.6s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **


Xcode's output:
↳
    Invalid depfile: /Users/MY_APP_NAME/PACKAGE_NAME/app/.dart_tool/flutter_build/9a159911376355ed7b90130da2eaf0aa/kernel_snapshot.d
    Invalid depfile: /Users/MY_APP_NAME/PACKAGE_NAME/app/.dart_tool/flutter_build/9a159911376355ed7b90130da2eaf0aa/kernel_snapshot.d
    Invalid depfile: /Users/MY_APP_NAME/PACKAGE_NAME/app/.dart_tool/flutter_build/9a159911376355ed7b90130da2eaf0aa/kernel_snapshot.d
    Invalid depfile: /Users/MY_APP_NAME/PACKAGE_NAME/app/.dart_tool/flutter_build/9a159911376355ed7b90130da2eaf0aa/kernel_snapshot.d
    Error: Couldn't resolve the package 'shared_preferences' in 'package:shared_preferences/shared_preferences.dart'.
    ../lib/ui/home/home_screen.dart:29:8: Error: Not found: 'package:shared_preferences/shared_preferences.dart'
    import 'package:shared_preferences/shared_preferences.dart';
           ^
    ../lib/ui/home/home_screen.dart:871:37: Error: The getter 'SharedPreferences' isn't defined for the class '_HomeScreenState'.
     - '_HomeScreenState' is from 'package:PACKAGE_NAME/ui/home/home_screen.dart' ('../lib/ui/home/home_screen.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'SharedPreferences'.
        final sharedPreferences = await SharedPreferences.getInstance();
                                        ^^^^^^^^^^^^^^^^^
    ../lib/ui/home/home_screen.dart:893:37: Error: The getter 'SharedPreferences' isn't defined for the class '_HomeScreenState'.
     - '_HomeScreenState' is from 'package:PACKAGE_NAME/ui/home/home_screen.dart' ('../lib/ui/home/home_screen.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'SharedPreferences'.
        final sharedPreferences = await SharedPreferences.getInstance();
                                        ^^^^^^^^^^^^^^^^^
    Unhandled exception:
    FileSystemException(uri=org-dartlang-untranslatable-uri:package%3Ashared_preferences%2Fshared_preferences.dart; message=StandardFileSystem only supports file:* and data:* URIs)
    #0      StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:34:7)
    #1      asFileUri (package:vm/kernel_front_end.dart:614:37)
    #2      writeDepfile (package:vm/kernel_front_end.dart:754:21)
    <asynchronous suspension>
    #3      FrontendCompiler.compile (package:frontend_server/frontend_server.dart:570:9)
    <asynchronous suspension>
    #4      starter (package:flutter_frontend_server/server.dart:85:12)
    <asynchronous suspension>
    #5      main (file:///opt/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:13:24)
    <asynchronous suspension>
    Failed to package /Users/MY_APP_NAME/PACKAGE_NAME/app.
    Command PhaseScriptExecution failed with a nonzero exit code
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Analyzing workspace
    note: Constructing build description
    note: Build preparation complete
    /Users/MY_APP_NAME/PACKAGE_NAME/app/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.5.99. (in target 'AppAuth' from project 'Pods')
    /Users/MY_APP_NAME/PACKAGE_NAME/app/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.5.99. (in target 'GoogleSignIn' from project 'Pods')

Could not build the application for the simulator.
Error launching application on iPhone 12 Pro Max.

One of the solutions that looked promising was deleting two files; kernel_snapshot.d and kernel_snapshot.stamp however that also didn't work for me. But I went to the path where these two files were residing. You can have a look into the folders and files structure in the following screenshot:

The folders and files I deleted

So what I did is actually delete those files that have been selected in the following screenshot and then try running the app as usual on the simulator. And it worked.

Prettypretty answered 13/3, 2022 at 15:21 Comment(0)
D
2

This happened to me, try to delete unused imports in your project!

Diabolo answered 31/1, 2024 at 3:36 Comment(0)
T
1

I experienced this. At first you have to check if you added the related dependencies on the pubspec.yaml file like below:

web_socket case ==>

( on pubspec.yaml )

dependencies: web_socket_channel: ^1.1.0
flutter: sdk:flutter

Truman answered 13/12, 2020 at 22:56 Comment(0)
H
1

If you're on VS code "try flutter clean then flutter run" on terminal

Hangnail answered 13/4, 2021 at 8:3 Comment(0)
S
1

Fixing problems in "Dart Analysis" tab solved the problem enter image description here

Sculpturesque answered 24/1, 2024 at 3:2 Comment(0)
A
0

I had exactly the same error and later on came to find out that I had imported web-only dependency in my pubspec file.

In my case.

firebase: ^5.0.0

This is only for web.

Alleen answered 25/12, 2020 at 16:25 Comment(0)
H
0

I figured that out the issue was caused by import 'package:firebase/firebase.dart'; in my project to Fix it delete that import

Hexamerous answered 18/6, 2021 at 16:0 Comment(0)
G
0

In my case, I had the same problem and solution:

flutter clean . 
 
flutter create .

This is a solution that I always try before almost any problem, then if it is not solved I see it in ..

Garrulity answered 14/7, 2021 at 14:3 Comment(0)
O
0

Take a closer look if you have added such an import?

    import 'package:firebase/firebase.dart';

If so, this is for the web. If you are writing a mobile application, then it is better to use such an import :

    import 'package:firebase_auth/firebase_auth.dart';

This could be a potential error.

Optimistic answered 3/8, 2021 at 16:2 Comment(0)
H
0

Check for any import which is related to browser or http and if your target platform is mobile then you might not need browser import and you can remove it.

In my case, I have removed this.

import 'package:dart_web3/browser.dart';
Henceforth answered 8/3, 2022 at 12:32 Comment(0)
R
0

Someone has a solution to delete kernel_snapshot.d and kernel_snapshot.stamp

Well, I did but error not gone. What i did else is to check other errors and other errors was coming from Stripe Package. So i commented like this #flutter_stripe ^2.1.1 on pubspec.yaml and also, do Pub get: Note : Any error you see after commented or removed sdk package on pubs make sure you remove those errors else, after that, clean build folder on xcode and run pod install. The error gone. For you and anyone else, check other errors below the red or yellow highlight on Xcode. You may see other error which may not shown on Buldtime Nav. also make sure you use the latest Xcode Version.

Rachal answered 7/5, 2022 at 23:34 Comment(0)
L
0

It's easy. The way around it is to look on the home page or the main page, comment out or delete the 'import dart.html' and save, and then run flutter run. You should be good to go.

Livesay answered 7/2, 2023 at 16:46 Comment(0)
C
0

Before running 'flutter pub get'

Go to the dependencies folder e.g. or whichever your app is pointing to ...

C:\Users\Administrator\AppData\Local\Pub\Cache\hosted\pub.dev

Look for the dependency that is misbehaving and just delete it.

Then run 'flutter pub get' to re-download it

flutter pub get
Controversy answered 13/2, 2023 at 14:17 Comment(0)
F
0

check your code properly, dart may have automatically imported some packages that are not necessary. check your imports very well, remove all imports not that are from you. In my case this was the import that was causing the error

"import 'dart:nativewrappers/_internal/vm/lib/ffi_allocation_patch.dart';"

I removed it and my code started working again.

Federicofedirko answered 24/5, 2024 at 12:57 Comment(0)
S
0

One of the simplest way :

flutter clean

flutter pub get

flutter run

that's it

Spew answered 7/6, 2024 at 6:33 Comment(0)
R
0

In my case i updated my flutter version and had to update my intl v0.19. here are the steps i took to solve my issue. I wasnt interested in using flutter Localization so i deleted the l10n.ymal.

Had to remove this line from my pubspec.ymal

After thus run: flutter clean && flutter pub get

Hope this helps.

Rebirth answered 21/6, 2024 at 20:13 Comment(0)
S
-1

I add this code it will run

import 'package:flutter/material.dart' show BuildContext, Colors, Column, Expanded, Key, MainAxisAlignment, MaterialApp, Row, Scaffold, Size, SizedBox, StatelessWidget, Text, TextButton, Widget, runApp;
Sisterly answered 12/11, 2022 at 20:47 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Negrillo

© 2022 - 2025 — McMap. All rights reserved.