-
Notifications
You must be signed in to change notification settings - Fork 136
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
"document is not defined" error in NextJS project #4
Comments
I'm seeing that his error is coming from next's proclivity to render on the server side. Generally, when doing dom level things like adding script tags, the best practice is to either
In this case, simply importing the component throws the error and all imports must happen at the top level, so these approaches don't work. Could there be a way to package the library differently? |
Hi @jde You are right. The issue here is that if I don't compile with webpack, Next.js will also throw an error complaining since it won't allow importing css modules within the package folder in node_modules. So the issue is in the webpack compile configuration which to be honest I'm not great at webpack configs. So until I refactor the css modules approach to use the Here is an example of how I currently use it with Next
Hope this helps. |
Thank you so much for providing this library! I'm looking to incorporate it into my project, which is built with Nextjs.
I've imported and used the Scheduler component in one of my components:
`
import React, { useState } from 'react'
import { Scheduler } from "@aldabil/react-scheduler";
`
When I hit the page, I see the following errors in the console:
error - ReferenceError: document is not defined at s (/Users/jde/dev/github/jde/platform/node_modules/@aldabil/react-scheduler/dist/Scheduler.js:1:4194)
I haven't been able to figure out why the document object isn't available in my project while it is available in the Create React App based example. Could it be a difference in the way Nextjs exposes the document element?
Looking into the source code, I'm seeing that the scheduler compiles down to use the basic document functions createElement, createTextNode, etc... Is is possible that this source code could be compiled differently to use other element creation functions?
A last thought I had was whether or not it makes sense to import the
dist/SchedulerComponent.js
directly, as that is the react/jsx code which may be able to be compiled into the project along with all my classes.Thanks again for maintaining the project. Any thoughts on how to integrate into my stack would be much appreciated!
The text was updated successfully, but these errors were encountered: