Polymer / tools

Polymer Tools Monorepo
BSD 3-Clause "New" or "Revised" License
430 stars 200 forks source link

Vulcanize is looking for scripts in the wrong place #1855

Closed shaunnetherby closed 5 years ago

shaunnetherby commented 8 years ago

I have a polymer element that includes a script, in my example it includes requirejs.

<link rel="import" href="../polymer/polymer.html"/>
<script src="../requirejs/require.js"></script>

With inlineScripts: true the vulcanize process now expects the require.js file relative to the location of the vulcanized file rather than the polymer file.

ERROR finding resources/components/requirejs/require.js

I'm expecting the file to be somewhere else -> resources/external/bower/requirejs

This just showed up in 1.14.1. We are looking into locking down our version to 1.14.0 to fix our build pipeline.

nelsonsilva commented 8 years ago

:+1: experienced the same. Had to shrinkwrap dependencies in several projects. At least this time we could use shrinkwrap, for polymer dependencies we ended up zipping them up in "bundles" since bower doesn't have a shrinkwrap alternative. Semver is used in tagged/released versions across polymer so it's currently impossible to get proper reproducible builds and things sometimes break with patch version changes. I hope the move to npm 3 happens quickly!

snowbillr commented 8 years ago

:+1: Seeing the same issue (using grunt-vulcanize). I have a polymer element living in bower_components that includes a script from a relative path and have inlineScripts: true in the config. Now vulcanize is looking for the included script relative to the source directory of the file that I'm vulcanizing, instead of where the polymer component lives.

Unfortunately for people using grunt-vulcanize, we can't downgrade our version of vulcanize. Any suggestions for a quick fix now? This is causing our builds to fail :disappointed:

nelsonsilva commented 8 years ago

@billnreed just run npm shrinkwrap and edit the shrinkwrap file replacing 1.14.1 with 1.14.0 and you should be good to go.

snowbillr commented 8 years ago

Thanks @nelsonsilva! First time I've used npm shrinkwrap, worked perfectly :smile:

suchipi commented 8 years ago

I'm having a similar issue. Using inline scripts, I am trying to build the contents of dev/index.html using underscore from bower_components/underscore/underscore-min.js via dev/lib/underscore.html (which dev/index.html imports). dev/lib/underscore.html contains:

<script src="../../bower_components/underscore/underscore-min.js"></script>

The two .. are to move out of lib and then out of dev, to the project root.

This builds correctly in 1.14.0, but in 1.14.1, it looks one directory higher than it should. Assuming a structure like ~/project/bower_components/..., it looks in ~/bower_components/.... I tried changing dev/lib/underscore.html to look up one fewer directory:

<script src="../bower_components/underscore/underscore-min.js"></script>

But this causes it to look in ~/project/dev/bower_components/... (as it should).

Reverting to 1.14.0 for now.

gstroup commented 8 years ago

+1 used npm shrinkwrap file to lock in version 1.14.0 for now.

dfreedm commented 8 years ago

This is probably due to https://github.com/Polymer/vulcanize/blob/master/lib/vulcan.js#L226, now that paths are resolved to mainDocUrl before inlining, whereas before the path was modified from each import document recursively.

dfreedm commented 8 years ago

Oh, no this is probably caused by https://github.com/Polymer/vulcanize/blob/master/lib/vulcan.js#L237-L256, where any scripts after imports are moved to body to preserve execution order. Those scripts should be repath'd like the bodyFragment above.

dfreedm commented 8 years ago

Released v1.14.2 which will make sure scripts moved to <body> have the right path in src.

gstroup commented 8 years ago

Looks like this issue has popped up again. If I roll back to 1.14.8, then no problem.

MattMcNam commented 8 years ago

Seeing this on 1.14.8 with grunt-vulcanize on Windows 10, works fine on OS X & Linux. Running from C:\Users\matt\Dev\... gives me Fatal error: ENOENT: no such file or directory, open 'C:\bower_components\iron-flex-layout\iron-flex-layout.html' nodecg/nodecg#185 with the following added to that branch:

git diff gruntfile.js
diff --git a/gruntfile.js b/gruntfile.js
index b2d20e6..bd0737e 100644
--- a/gruntfile.js
+++ b/gruntfile.js
@@ -70,9 +70,16 @@ module.exports = function (grunt) {
                                }
                        }
                },
+               crisper: {
+                       dist: {
+                               src: './lib/dashboard/public/elements/elements.vulcanized.html',
+                               dest: './lib/dashboard/public/elements/elements.min.html'
+                       }
+               },
                vulcanize: {
                        dist: {
                                options: {
+                                       inlineScripts: true,
                                        redirects: [
                                                '/bower_components|./bower_components',
                                                '/dashboard/elements|./lib/dashboard/public/elements'
@@ -86,5 +93,5 @@ module.exports = function (grunt) {
                }
        });

-       grunt.registerTask('default', ['browserify:dist', 'vulcanize:dist']);
+       grunt.registerTask('default', ['browserify:dist', 'vulcanize:dist', 'crisper:dist']);
 };
CesarAntonNBCU commented 7 years ago

Can't use npm-shrinkwrap since that requires NPM v2 or lower, that is extremely outdated so it's not an option.