0

I have React.js project that needs to convert to a Next.js

This project has a file data-pulse-provider.js

import { logMessage, } from './helpers';
import $ from 'jquery';


require('signalr');
window.jQuery = $;

var DataPulseProvider = /** @class */ (function () {
 //...
}());
export { DataPulseProvider };

Here I am getting an error

Error: jQuery was not found. Please ensure jQuery is referenced before the SignalR client JavaScript file.

I think this window object is not available all the time in next.js. The solution I found was use dynamic imports with SSR false and then use useEffect to window object-related code. But this is a pure js file hence I can't use the useEffect or something like that. So how can I fix this issue?

Any help! Thanks in advance.

4
  • 1
    Why not importing module in useEffect? Commented Oct 22, 2021 at 7:59
  • This is just a JS file. Not a jsx file Commented Oct 22, 2021 at 8:22
  • So? It is file that you are importing to your app as a module, there is no difference what extension it has(as long it is javascript that is) Commented Oct 22, 2021 at 8:32
  • As suggested, you can dynamically import data-pulse-provider in your component's useEffect. See Dynamically import abcjs in Next.js for an example. Commented Oct 22, 2021 at 18:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.