Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't resolve local files without a '.js' extension #26

Open
vdegenne opened this issue Sep 27, 2019 · 2 comments
Open

can't resolve local files without a '.js' extension #26

vdegenne opened this issue Sep 27, 2019 · 2 comments

Comments

@vdegenne
Copy link

vdegenne commented Sep 27, 2019

Today I am trying out koa and this middleware which is nice for quickly creating projects using web components that uses es-module imports.

One problem I identified is the middleware is not able to resolve local files without a '.js' extension.
I am using mwc-dialog and mwc-button in my project and when I start the server and try to load the page I have a lot of missing scripts. Here's a capture :

I think the problem is koa-node-resolve thinks these local files are in the node_modules folder.

In the following capture :

There are three things to notice :

  • the red circle on the right clearly shows that the filepath is missing an extension
  • the red circle on the left clearly shows that the filepath is local (and maybe this middleware can use this information to treat it as is.)
  • the third thing to notice is the weirdness in the way this middleware is using both slashes, back and double backslashes in the resolved paths.

Now I don't know if this is because I am using Windows and If the problem occurs only when the middleware is run on this system, but I am really hoping you will fix this issue anytime soon.
It's either something to fix in this middleware or constraining the Polymer team to use the .js extension everytime they try to import a local script.

Thanks in advance for your help.

@vdegenne
Copy link
Author

I just have realized I said irrelevant things.
First the problem is not the middleware ignoring the nature of these files, in fact it knows these files are local and that is why it's not trying to resolve and change the path in the resolution process.
The problem is the server not being able to resolve these files because, still, they lack an extension.

I guess I could just write a koa middleware myself that checks if the file exists and serve it even if it doesn't have an extension but usually these files are also es-modules so I think that should be implemented directly into this middleware.

@vdegenne
Copy link
Author

Ok just so you know the issue is coming from I'm running the program from Windows.
I tried to run the same code from linux and the slashes are corrects, the missing extension path are well resolved and everything is working great.

I think this kind of solve my problem but again so you know this middleware fails with Windows paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant