ReferenceError: Polymer is not defined - polymer

When i start gulp serve am facing following error
ReferenceError: Polymer is not defined
http://localhost:5000/elements/my-greeting/my-greeting.html:30
ReferenceError: Polymer is not defined
http://localhost:5000/elements/my-list/my-list.html:30
Here is code of my-greeting.
<script>
(function() {
'use strict';
Polymer({
is: 'my-greeting',
properties: {
greeting: {
type: String,
value: 'Welcome!',
notify: true
}
}
});
})();
</script>

You must include the reference to polymer in your list.html file:
<link rel="import" href="../bower_components/polymer/polymer.html">
Are you sure it was included?

Although I am serving through IIS, I was having the same kind of issues as you.
Error: Polymer is not defined
<unknown> at /GooglePolymer/starterKit/app/elements/my-greeting/my-greeting.html:30
<unknown> at /GooglePolymer/starterKit/app/elements/my-greeting/my-greeting.html:41
Chrome DevTools was throwing a 404, telling me It could not find the bower component polymer.html
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/GooglePolymer/starterKit/app/bower_components/polymer/polymer.html
For some reason I can not explain the link references in the files are not functioning correctly and not linking up enough levels to the bower_components. Hence not finding file.
Solution: I copied the bower_components folder into app and boom it worked. I hope this helps with your problem.

Import polymer.html in your custom element files.

Locate the .bowerrc file and be sure that the entry is pointing to the directory scaffold location where the bower components are residing.
Even if your code "links" to the exact location of the project bower components, the .bowerrc file overrides the directive [most importantly for Polymer]. In my case, the bowerrc file was claiming the bower components were located in the public [application, NOT project] directory.
A number of the Polymer examples offset the bower components by a sub-directory or two so that adding a bower component using npm results in a mismatch that can manifest itself as dual [dueling] bower component sources. For example, running a bower request such as npm install --save whatever always installs to the project directory regardless that the .bowerrc file points to the public directory.
Having said all that, placing the bower components in both the project directory, say firebaseTest, AND the application directory, say public [firebaseTest->public] fixed multiple bower component issues. And these were "Whack-a-Mole" type bugs in which one fix would cause a fix breaking other bug.
I was having "[paper-listbox::_flattenBehaviorsList]: behavior is null, check for missing or 404 import" issues that messed up a dropdown component.
It appears that the material components themselves have internal dependency reference issues meaning that some subset of material components need to be in the project directory and others in the application directory. I just dropped identical bower-component directories in both places for the short term.

Related

Polymer: Failed to load resources after build

I'm new to polymer. I've followed a couple of tutorials to learn the base of the library. However, I always encounter a problem after building the app.
Here is a summary how to reproduce my problem.
polymer --version //returns 1.6.0
mkdir poly-app
cd poly-app
polymer init // Select polymer-2-application
polymer serve --open // works fine
polymer build
polymer serve build/default --open // works fine
Now, I would like to export my code to my web server. I copy paste the content of /poly-app/build/default and I paste it on my web server. When I try to access it, it get errors such as:
Failed to load resource: the server responded with a status of 404 (Not Found)
I found that the problem comes from the following lines of code in /poly-app/build/default/index.html:
<script src="/bower_components/webcomponentsjs/webcomponents-loader.js"></script>
<link rel="import" href="/src/poly-app-app/poly-app-app.html">
In order to fix the problem, I need to remove the first / in the src and href attribute.
<script src="bower_components/webcomponentsjs/webcomponents-loader.js"></script>
<link rel="import" href="src/poly-app-app/poly-app-app.html">
Apparently I need to do this manually every time I build the app. Is there any other way to fix automatically?
Thanks a lot!
I believe you are trying to serve it from a non root path on your website?
In that case you should set the basePath property of the build configuration to the respective path and the generated code should populate the <base> tag with the needed information so the urls are working.

switching from bower_components to node_modules crashes Polymer project

I have a working Polymer project when I have all my links pointing to the bower_components folder, however, when I change to node_modules I get the following message when I run
polymer serve
"Failed to load resource: the server responded with a status of 404 (Not Found)"
with the URL being:
http://127.0.0.1:8081/node_modules/#polymer/polymer/polymer.html
This is correct since the Polymer team changed polymer.html to polymer.js
However, where is this done and how can I use polymer using yarn (which saves in node_modules)?
Edit:
I think I found the culprit. When I tried to find iron-icons (mind the 's'), I could only find it on yarn which saves to node_modules. When I load the node module iron-icons I get the above-mentioned error message.
So I point to the bower_component iron-icon (mind you, no 's') but that doesn't provide the extensive library of icons I have with the yarn package:
on Yarn: https://yarnpkg.com/en/package/#polymer/iron-icons
but no such thing with Bower: https://bower.io/search/
Why?!

Angular dependencies not being included from local files

I have the following lines on my index.html file to include various dependencies
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
However, It keep getting the following error.
It seems like it is trying to retrieve angular and other dependencies from localhost.
How do I resolve this error?
Check your server's base filepath, its should be set to a directory level just above bower_components/
Example : if your directory structure is app/bower_components/xx/xx.js, set your server's static serve path to app/
Assuming that you are using node and express as your server, use this link for knowledge on setting static paths.
I don't see any other problem with this. As the error is 404 which means your files are not being located by the server.
check if file are already in the real path, if not, install them with: bower install

Autodesk Viewer Markup extension - can't compile from sources

I'm trying to achieve similar viewer annotations like official demo:
lvm-react
I read official blog post and use files from Autodesk Extensions github:
http://adndevblog.typepad.com/cloud_and_mobile/2016/04/markup3d-sample-for-view-data-api.html
But I can't compile extensions from sources (create bundle.js). Tried just npm install, but there are many errors like:
ERROR in ./src/Viewing.Extension.VisualReport/PieChart/PieChart.js
Module not found: Error: Cannot resolve module 'EventsEmitter' in MY_FILES
and
ERROR in ./src/Viewing.Extension.StateManager/Viewing.Extension.StateManager.scss
Module parse failed: /MY_PATH/library-javascript-viewer-extensions-master/src/Viewing.Extension.StateManager/Viewing.Extension.StateManager.scss Unexpected token (2:0)
You may need an appropriate loader to handle this file type.
I also installed webpack using npm, but without result, there are still many errors.
There was a few loaders missing from the webpack build production config. It is fixed now and you should be able to build all extensions. Please use the latest version from the repo.
When testing your extensions, I recommend you use npm run build-dev command, so the generated extensions files will not be minified and have source-map enabled, so you can easily debug them in browser console. When building for production, you can use npm run build-prod.
You can also remove the various entries from the webpack config to build only the extensions you are interested in, for example:
module.exports = {
devtool: 'eval-source-map',
entry: {
'Viewing.Extension.Markup3D':
'./src/Viewing.Extension.Markup3D/Viewing.Extension.Markup3D.js',
},
// ... rest of the config ...
You may also want to change the output path, in my config the output is outside of the extensions directory, directly in the project using them:
output: {
path: path.join(__dirname, '../../App/dynamic/extensions'),
filename: "[name]/[name].js",
libraryTarget: "umd",
library: "[name]",
watch: true
},
In addition to including the extension file to your project, you should also make sure that you include the babel polyfill (from node_modules/babel-polyfill/dist/polyfill.min.js) before any extension script.
Hope that helps, let me know if you have any further trouble using those extensions.

Understanding Polymer 1.x Polymer Starter Kit file structure as it relates to bower_components imports

In the Polymer Starter Kit, every reference to the bower_components subdirectory refers to a node just below the app directory. However, (at least in my version of PSK) the bower_components subdirectory is one level up from the app directory. In other words, the bower_components subdirectory is actually located in the project root directory.
Am I just miscounting my directory nodes? Or does this have something to do with how gulp and maybe vulcanize work? Or is it something else altogether that I'm not understanding?
For example, in index.html there is this script tag:
index.html
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
which suggests the bower_components directory is at the same level as index.html. But it's not. bower_components is actually one level up.
Same for element imports.
Compilation of responses from Polymer Slack Site:
Response #1:
yeah, gulp basically builds everything into a build and the web server serves the build folder instead of the project. I don’t remember what’s the name of the build folder in starter kit in particular, but for most project it works as I described
Response #2:
it’s specific to PSK. The local server mounts that directory and serves it as if it were inside app. I just sent in a PR to change this because it’s confusing