Polymer / polymer

Our original Web Component library.
https://polymer-library.polymer-project.org/
BSD 3-Clause "New" or "Revised" License
22.05k stars 2.01k forks source link

Cannot resolve module specifier because componentDir is without effect #5624

Closed mark-kubacki closed 4 years ago

mark-kubacki commented 4 years ago

Argument --component-dir, "componentDir" in polymer.json is not being used, and components are not found if components are being installed in a directory other than node_modules.

Might be related: Polymer/tools#431

Steps to Reproduce

Any (third-party) components shall go into directory static; this will be the directory structure created in this example:

.
├── polymer.json
├── package.json
├── public
│   └── index.html
├── static
│   ├── @polymer
│   │   ├── …
…
└── .yarnrc

This is polymer.json:

{
  "entrypoint": "public/index.html",
  "npm": false,
  "componentDir": "static"
}

.yarnrc is:

--*.modules-folder ./static

Let package.json be (excerpt):

{
  "name": "foo",
  "version": "1.0.0",
  "private": true,
  "flat": true,
  "dependencies": {
    "@polymer/paper-button": "^3.0.1",
    "@webcomponents/webcomponentsjs": "^2.4.1"
  }
}

Create public/index.html with:

<!DOCTYPE html>
<html>
<title>foo</title>
<script src="/static/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script type="module">
  import '@polymer/paper-button/paper-button.js';
</script>

<section>
  <paper-button class="pink">link</paper-button>
  <paper-button raised class="indigo">raised</paper-button>
</section>
</html>

Now execute:

yarn install
# This will populate static/, which we want.

# yarn global add polymer-cli

~/.yarn/bin/polymer build
# error

Expected Results

  1. polymer (polymer-cli) exits with code 0 (success), i. e. no errors.
  2. Directories build/default/public and build/default/static do exist…
  3. build/default/static exists and contains the components, just like a node_modules would (which not using is the point here).

Actual Results

info:   Clearing build/ directory...
debug:  build config loaded:
…
file:///home/…/…/site/public/index.html(100,2) warning [cant-resolve-module-specifier] - Cannot resolve module specifier with resolution algorithm: node
Could not resolve module specifier "@polymer/paper-button/paper-button.js" in file "/home/…/…/site/public/index.html_script_1.js".

Specifically, although componentDir points to static/ and static/@polymer/ exists, the component does not get found because folder static is not considered when resolving.

Neither does changing the algorithm from node to none solve this, nor (in combination with) does toggling "npm": true to "npm": false.

Creating a symlink static ← node_modules is not what I want, because the output shall contain no node_modules by having set componentDir accordingly.

arthurevans commented 4 years ago

Yes, this appears to be a duplicate of https://github.com/Polymer/tools/issues/431 so I'm going to close this one.