question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change imports to relative paths

See original GitHub issue

Hi, we are starting a new Polymer 3 project and want to use lit-element if possible. We prefer to just use the source files as is when developing to exclude any extra build steps and it works perfectly in previous projects (using Polymer 2 and 3.0.0-pre). With ES6 imports this is super handy, how come that you don’t write your imports as relative paths?

When trying the same approach with lit-element we get the following error because of this:

Uncaught TypeError: Failed to resolve module specifier "@polymer/lit-element/lit-element.js". Relative references must start with either "/", "./", or "../".

Also polymer serve will not work since it gets the URL’s wrong. With polymer build it works fine but having to build before each page load is inconvenient.

Would you consider changing all the import statements so that they are relative to the file that is importing? This would remove the need to build entirely for development (and possibly even for pages that targets recent browsers), it does not make much sense to me to have a build step just to change import paths.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jyouncecommented, Jun 25, 2018

Hi guys, sorry to comment on a closed issue but I just want to make sure of something.

Myself and others are creating individual components available for anyone to use via Polymer 3. So far, so good, super easy to consume and use. Recently, I tried to convert to lit-element and ran into the issue above.

So let’s say the conversion was successful. Are you guys saying that anyone who wants to use the converted component now has to use a JS Module Bundler?

1reaction
simonh1000commented, Aug 24, 2022

I get the same error after following https://lit-element.polymer-project.org/guide/start

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring the Style of Imports in JavaScript and TypeScript
To control that for auto imports, open the Imports tab and check the option “Use paths relative to the project, resource or sources...
Read more >
Auto Import Relative Path - Visual Studio Marketplace
Launch VS Code Quick Open ( Ctrl+P ), paste the following command, and press enter.
Read more >
Getting rid of relative paths in imports using webpack alias
Traditionally we import a component by mentioning the directory using combination of dots and slashes. The problem with this approach is that this...
Read more >
Auto import in Visual Studio Code only offering absolute path ...
In Visual Studio Code, menu File → Preferences → Settings → User Settings, "typescript.preferences.importModuleSpecifier": "relative".
Read more >
How Pros Get Rid of Relative Imports - DEV Community ‍ ‍
Paths allow us to aggregate a list directories under a predefined name and drastically reduce the length of the imports.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found