Polymer / tools

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

Polyserve: If a project is called "nn", includes from the "nn" directory to resolved packages will fail #3456

Open mercmobily opened 5 years ago

mercmobily commented 5 years ago

Hi,

This is a very edge case. I am mainly reporting it in the hope that it could possibly hide a bigger problem. Basically, is the package name in package.json has the same name as the directory that contains a javascript file, importing from node_modules from that javascript file will fail.

That was a mouthful. It's easier to see by looking at this: https://glitch.com/~mire-rhodium

Assume your package.json is:

{
  "name": "nn",
  "version": "0.0.1",
  "description": "",
  "scripts": {
    "start": "./node_modules/polymer-cli/bin/polymer.js serve"
  },
  "dependencies": {
    "lit-element": "^2.2.1",
    "polymer-cli": "^1.9.11"
  }
}

And that your index.html is:

<head>
  <script type="module" src="./TestElement.js"></script>
</head>
<html>
  <h1>Elements test page</h1>
    <test-element></test-element>
  </script>
</html>

And that your TestElement.js is:

import { LitElement, html } from 'lit-element'
import './nn/InputText.js'

class TestElement extends LitElement {
  render () {
    return html`
      <nn-input-text labelBefore>
      </nn-input-text>
    `
  }
}
customElements.define('test-element', TestElement)

And finally your nn/InputText.js is: (NOTE THAT nn/)

// THE FOLLOWING LINE WILL FAIL
import { LitElement, html, css } from 'lit-element'
export class InputText extends LitElement {

  render () {
    return html`<input type="text" id="_native">`
  }
}
customElements.define('nn-input-text', InputText)

The import in nn/InputText.js will FAIL:

GET https://mire-rhodium.glitch.me/nn/node_modules/lit-element/lit-element.js net::ERR_ABORTED 404 ImputText.js (1)

Renaming the project to "nn2" (or anything really) in package.json "fixes" the problem.

I hope the glitch helps!

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.