Skip to content

Builder errors out on files it's supposed to generate #1718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Meai1 opened this issue Aug 6, 2018 · 7 comments
Closed

Builder errors out on files it's supposed to generate #1718

Meai1 opened this issue Aug 6, 2018 · 7 comments

Comments

@Meai1
Copy link

Meai1 commented Aug 6, 2018

> pub run build_runner serve --output=build
[SEVERE] build_web_compilers|ddc on web/index.module:
Error compiling dartdevc module:example|web/index.ddc.js

[error] Target of URI doesn't exist: 'index.jsx.dart'. (/web/index.dart, line 11, col 8)
[error] The function 'r' isn't defined. (/web/index.dart, line 17, col 11)

Please fix all errors before compiling (warnings are okay).
}
[WARNING] build_web_compilers|entrypoint on web/index.dart:

Unable to read example|web/index.ddc.js, check your console or the `.dart_tool/build/generated/example/web/index.ddc.js.errors` log file.
[INFO] Running build completed, took 5.3s
[INFO] Caching finalized dependency graph completed, took 184ms
[SEVERE] Failed after 5.5s
Serving `web` on http://localhost:8080

Dart VM version: 2.0.0-dev.69.5 (Tue Jul 31 15:05:14 2018 +0200) on "linux_x64"

I have attached my full source code because this is weird. I dont see how this can be my fault, it has to be a bug.

example.zip

@jakemac53
Copy link
Contributor

The if (strContent.contains("<template>")) { check is returning false and I don't see that code in the index.dart. I confirmed the ordering of builders is correct though, so if you fix that everything should work.

@Meai1
Copy link
Author

Meai1 commented Aug 6, 2018

@jakemac53 okay I see, the reason why I made such an obvious error is because there seems to be a caching problem and nothing I did changed the behavior of my builder so I got more and more confused.
Try changing the template after it is corrected and no matter how many times I restart pub serve, it wont update the index.jsx.dart when I edit the index.dart.
Surely the purpose of the builder is to keep the output synced with the input file so that must be the bug then.

Change it first to a valid anything with <template> around it: var x = r(""" <template><p>hi</p></template> """);

@jakemac53
Copy link
Contributor

Ah, I see you are reading the file directly with dart:io, in order for the build system to notice changes you need to use the buildStep to read/write files.

Basically, change var strContent = await new File(buildStep.inputId.path).readAsStringSync(); to var strContent = await buildStep.readAsString(buildStep.inputId).

@jakemac53
Copy link
Contributor

This also makes your builder more portable, in can read generated files and run in other environments that don't have dart:io or where the source files live in some other place.

@Meai1
Copy link
Author

Meai1 commented Aug 6, 2018

Cool now it works, thank you. Btw, it was also very confusing for me that print() doesnt seem to work 99% of the time but it does work when I tried to print out the contents after reading it from the buildStep.
That had me perplexed for a long time until I eventually changed all my print()s to log calls. Printing used to work with transformers normally.

@jakemac53
Copy link
Contributor

Printing does work but it logs at the info level which we will usually overwrite to cut down on noise in the logs. You can remove that behavior with the -v flag but you will get a lot of logs in your output.

@natebosch
Copy link
Member

We'll also switch print to behave like log.warning instead so those messages stand out.
#1720

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

No branches or pull requests

3 participants