skip to Main Content

I ran into a problem importing js files (these are libraries). I am using NextJS 14.1.3 and ReactJS 18.2.0.

Here is the path to these files
Here is the path to these files

Project structure
Project structure

This is the way I imported the files

import Script from 'next/script';

render() {
        const {Component, pageProps}: any = this.props;

        // During SSR, this will create new store instances so having `initialData` is crucial.
        // During the client-side hydration, same applies.
        // From then on, calls to `getStores()` return existing instances.
        const stores = getStores();

        return (
            <StoreProvider value={stores}>
                <Script
                    src='/public/js/LunaPass.1.6.8.js'
                    strategy="beforeInteractive"
                />
                <Script
                    src='/public/js/LPMessageRenderer.1.6.8.js'
                    strategy="beforeInteractive"
                />
                <Component {...pageProps} />
            </StoreProvider>
        );
    }

Error itself
Error in console

Has anyone encountered such a problem?

My expectation of my actions is to import js files and then use them in other pages.

2

Answers


  1. Chosen as BEST ANSWER

    I fixed by adding module.exports = {} in js file


  2. You don’t have to put the /public part you just have to use "/js/(script name)".

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search