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

Dynamic Import load .json? #2903

Closed
1 task done
jacobpdq opened this issue Sep 4, 2017 · 2 comments
Closed
1 task done

Dynamic Import load .json? #2903

jacobpdq opened this issue Sep 4, 2017 · 2 comments

Comments

@jacobpdq
Copy link

jacobpdq commented Sep 4, 2017

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

I expected to have my .json file returned.

Current Behavior

Instead, I was asked for 'module' or 'render' objects.

Steps to Reproduce (for bugs)

  1. Create a JSON file to import
  2. use dynamic(require) to import the file
  3. voila

Context

I'd like to use the dynamic import in a page-loading situation whereby my .md/json is loaded in on the prop-injection. Better than working with fetch as the export function is respected by next and the require baked-in.

@sergiodxa
Copy link
Contributor

sergiodxa commented Sep 9, 2017

You are able to do await import('path/to/file.json'), the next/dynamic module is for rendering dynamic React component but you don't need it to use async imports.

const data = await import('../data.json')
console.log(data);

👆 that works.

@timneutkens
Copy link
Member

Nice!

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants