如何在VisualStudio.com中成功执行polymer build命令?
Hey Andrea, sorry to hear you're hitting roadblocks getting your Polymer project built—let's work through the most common fixes since you already nailed the CLI installation. Here's a step-by-step breakdown to get polymer build working:
polymer.json Config The polymer build command relies entirely on your project's structure and the polymer.json config file in the root directory. If this file is missing or misconfigured, you'll run into errors every time.
First, confirm your project has the standard layout:
- Root directory with
index.html(your entrypoint) - A
src/folder containing your Polymer components - A valid
polymer.json(if you don't have one, runpolymer initand select your project template to generate a default config)
Here's an example of a basic, working polymer.json for a Polymer 3 project:
{ "entrypoint": "index.html", "shell": "src/my-app/my-app.js", "sources": [ "src/**/*", "images/**/*", "node_modules/**/*" ], "extraDependencies": [ "manifest.json", "service-worker.js" ], "builds": [ { "name": "production", "bundle": true, "js": { "minify": true, "compile": true }, "css": { "minify": true }, "html": { "minify": true } } ] }
Make sure the entrypoint, shell, and sources paths match your actual project files.
Version mismatches between the Polymer CLI and your project dependencies are a super common culprit.
First, check your CLI version with:
polymer --version- If you're on Polymer 3+, your project should use npm for dependencies (not Bower).
- If you're on an older version (Polymer 1/2), you'll need Bower for component management.
Ensure all dependencies are properly installed:
- For Polymer 3+: Delete
node_modulesandpackage-lock.json, then runnpm install - For Polymer 1/2: Delete
bower_componentsandbower.lock, then runbower install
- For Polymer 3+: Delete
Even with a correct config, these issues often break builds:
- "Entrypoint not found": Double-check the
entrypointpath inpolymer.json—make sureindex.htmlexists at that location. - Missing dependencies: Run
polymer analyzeto scan your project for missing components or npm packages, then install whatever's flagged. - Transpilation failures: If you're using ES6+ syntax that needs to work on older browsers, ensure your
buildsconfig includes thecompile: trueflag for JS (like in the example above).
Cached files or partial builds can cause weird errors. Start fresh with:
polymer clean
Then run the build with verbose logging to see exactly where things are failing:
polymer build --verbose
The verbose output will show you which file is causing issues, which dependency is missing, or where the config is broken.
If you're still stuck, create a new test project to verify the CLI works correctly:
polymer init polymer-3-application cd my-new-app polymer build
If this test build succeeds, compare the polymer.json, package.json, and project structure of the new app to yours—you'll likely spot a misconfiguration or missing file in your original project.
内容的提问来源于stack exchange,提问作者Andrea

