I'm trying to use Polymer on a new project, and was trying to avoid using Bower in favor of NPM for front-end dependency management.
The getting started page gives instructions for using Bower (and using a .zip file, etc...) but no mention of NPM.
I have used NPM by pointing directly at a GitHub repo before, but I cannot seem to get this to work for Polymer.
When I run this:
npm install [email protected]:Polymer/polymer.git#v1.0.5
I get this error:
npm ERR! notarget No compatible version found: git@'github.com:Polymer/polymer.git'
npm ERR! notarget Valid install targets:
npm ERR! notarget ["0.1.0","0.1.1","0.1.2","0.1.3","0.1.4","0.1.5"]
Is there something I'm missing, or do I need to bite the bullet and use Bower?
Step 1 − Install Polymer using the following npm command. Step 2 − Check the successful installation and version using the following command. Step 3 − Create a directory with the name of your choice and switch to that directory. Step 4 − To initialize your project, run the following command in your polymer-jsdirectory.
In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package. By default, npm install will install all modules listed as dependencies in package.
The npm install installs all modules that are listed on package. json file and their dependencies. npm update updates all packages in the node_modules directory and their dependencies.
Since the earlier answers, Polymer has now indeed become available on NPM. To install it:
npm i Polymer
Note that it doesn't include the standard elements collection; those can be found here:
npm i npm-polymer-elements
You can then include them in your HTML:
<!-- for custom elements -->
<link rel="import" href="/node_modules/@polymer/polymer/polymer.html"/>
<!-- for standard elements -->
<link rel="import" href="/node_modules/paper-button/paper-button.html"/>
<paper-button>click</paper-button>
Unfortunately loading Polymer through webpack currently doesn't seem possible yet, meaning if your node_modules
(or bower_components
) folder isn't in a publicly accessible location, you may want to make a Grunt/Gulp task to copy it over for after future updates...
The main problem with Polymer is that the tagged build commits don't have a package.json
, making it impossible to install them with npm
(e.g. see v1.1.1). This means that in order to install Polymer with npm
you'll need some helper tool. Perhaps the best candidate for this is Napa.
Napa is a package for installing git projects that do not have a (valid) package.json
. The npm page already explains how to use it, here a quick summary for Polymer:
npm install napa --save-dev
Update your package.json
to include this (replace x.y.z with the version you want):
{
"scripts" : {
"install" : "napa"
},
"napa" : {
"polymer" : "polymer/polymer#vX.Y.Z"
}
}
Note that napa
just clones the repo into the node_modules
folder, hence no dependencies of polymer will be installed alongside of it, but you can keep all of the configuration in your package.json
instead of having to use bower.
EDIT 2016/10/25
The Polymer team announced at the Polymer Summit 2016 that they will be looking into supporting npm
via yarn.
[sudo] npm install -g yarn
yarn add Polymer
yarn install --flat
OLD AWNSER
There is currently no way I know of to get polymer running with NPM.
Polymer is meant to work with Bower. All dependencies of a Polymer that are declared in https://github.com/Polymer/polymer/blob/master/bower.json like webcomponentsjs
will not be downloaded. Therefor if you don't want to download every dependency manually you should use bower.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With