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

Public folder not being recognized with absolute imports #149

Closed
fandy opened this issue Apr 21, 2020 · 1 comment
Closed

Public folder not being recognized with absolute imports #149

fandy opened this issue Apr 21, 2020 · 1 comment

Comments

@fandy
Copy link
Contributor

fandy commented Apr 21, 2020

<Logo src={require('/branding/logo.svg')} />

Does not work, but without the require it does (Next.js recognizes the absolute path starting from the public root folder). Does the plugin not work with absolute plugins, or does it require some additional config not mentioned in the docs?

@cyrilwanner

@cyrilwanner
Copy link
Owner

Hello,
the require in this case just works as any other require or import statement in your code. You also can't import another js file with an absolute path, since that would start at the root of your file system, so you also can't require an image with an absolute path.
If you are using typescript, you could set up a path alias (e.g. @public/) which points to your public folder so you don't have ../../../ etc in your code, but a normal absolute path will not work.

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

2 participants