question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Absolute path to package is presented in the build output assets

See original GitHub issue

Describe the bug When some package is using embroider-build/embroider, it includes the absolute path in the output assets. We discovered this by using the ember-fontawesome and we reported an Issue there and they redirected us to ember-get-config and we opened an issue there too but they redirected us to you.

Reproducible test case Here I’ve created a repo where the issue can be reproduced easily fa-test. If you want you can directly examine the vendor file.
Or get the repo, and do npm install and examine vendor...js file in dist folder, you should see an absolute path to one of the packages in your local machine.

Expected behavior We want deterministic builds that are absolute-path invariant (i.e. the build output shouldn’t depend on the machine or the project’s location in the file system). Sometimes we build on our local machine, but sometimes the build is done in some agent (CI/CD Azure for example). We want build outputs to be identical no matter the machine they are built on.

Desktop (please complete the following information):

  • Browser: Chrome
  • Version: 104.0.5112.81 (Official Build) (64-bit)

Additional context Please check the ReadMe file for more instructions about this issue.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ef4commented, Aug 11, 2022

Thanks for reporting.

I think the bug here is that we’re leaving runtime information in the build even in production builds that resolve all macros at build-time. I’m pretty sure this bit of code that includes the absolute paths isn’t getting used at all anyway.

The macros work differently in dev vs prod. In dev builds we do more work at runtime, which makes it much cheaper to switch between environments (like testing vs not-testing and browser vs fastboot). In prod builds we inline all the macro results at build time, which results in smaller, faster output at the cost of needing to produce entirely separate assets for different environments (primarily browser vs fastboot).

This bug probably only affects people on classic builds. Under embroider, this entire module gets optimized away because nothing is using it.

I think this might be the fix but I haven’t had a chance to test it:

diff --git a/packages/macros/src/babel/macros-babel-plugin.ts b/packages/macros/src/babel/macros-babel-plugin.ts
index 342f4e5b..385f2380 100644
--- a/packages/macros/src/babel/macros-babel-plugin.ts
+++ b/packages/macros/src/babel/macros-babel-plugin.ts
@@ -47,7 +47,7 @@ export default function main(context: typeof Babel): unknown {
     FunctionDeclaration: {
       enter(path: NodePath<t.FunctionDeclaration>, state: State) {
         let id = path.get('id');
-        if (id.isIdentifier() && id.node.name === 'initializeRuntimeMacrosConfig') {
+        if (id.isIdentifier() && id.node.name === 'initializeRuntimeMacrosConfig' && state.opts.mode === 'run-time') {
           let pkg = state.owningPackage();
           if (pkg && pkg.name === '@embroider/macros') {
             inlineRuntimeConfig(path, state, context);
0reactions
ef4commented, Sep 5, 2022

Fixed in #1245

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - Error: output.path needs to be an absolute path or
So... if I make the path absolute: "/dist/assets" or path: __dirname + "/dist/assets" then it serves up the files fine, and emits bundle.js,...
Read more >
consider "output" path in serve mode for assets configuration
today I udpate to last version of cli 1.4.7 tried ng build this get error : An asset cannot be written to a...
Read more >
Accessing package assets - Unity - Manual
To get the absolute path of a packaged asset, use the Path.GetFullPath() method. For example: string absolute = Path.GetFullPath(" ...
Read more >
Change the build output directory - Visual Studio (Windows)
Type in the path to generate output to (absolute or relative to the root project directory), or choose Browse to browse to that...
Read more >
Public Path - webpack
It allows you to specify the base path for all the assets within your application. ... Essentially, every file emitted to your output.path...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found