file.dart icon indicating copy to clipboard operation
file.dart copied to clipboard

Runtime exception on web when trying to DirectoryNode.clock

Open rrousselGit opened this issue 2 years ago • 3 comments

Here's some code to reproduce the issue:

// lib/main.dart
import 'package:file/memory.dart' as f;

void main() {
  final fs = f.MemoryFileSystem();
  final dir = fs.directory('/path');
  final dir2 = dir.childDirectory('another');
  final dir3 = dir2.childDirectory('path');
  final file = dir3.childFile('file.dart');

  file.createSync(recursive: true);
  file.writeAsStringSync('Hello, World!');

  print(file.path);
  print(file.readAsStringSync());
}

Then run:

dart compile js lib/main.dart

and create an html file using the generated JS, such as:

<html>
  <head> </head>
  <body>
    <script src="out.js"></script>
  </body>
</html>

Opening this HTML throws an error in the console:

node.dart:224 Uncaught TypeError: Cannot read properties of undefined (reading 'clock')
    at DirectoryNode.get$clock (node.dart:224:25)
    at DirectoryNode.RealNode$1 (node.dart:153:15)
    at Object.DirectoryNode$ (node.dart:198:3)
    at MemoryFile__doCreate_closure.call$2 (memory_file.dart:70:11)
    at MemoryFileSystemEntity_internalCreateSync_closure.call$5 (memory_file_system_entity.dart:202:19)
    at _MemoryFileSystem.findNode$4$followTailLink$segmentVisitor$visitLinks (memory_file_system.dart:269:17)
    at MemoryFile.internalCreateSync$2$createChild$followTailLink (memory_file_system_entity.dart:189:12)
    at MemoryFile._doCreate$1$recursive (memory_file.dart:64:18)
    at main (memory_file.dart:60:5)
    at js_helper.dart:2744:31

rrousselGit avatar Apr 25 '23 16:04 rrousselGit