Prebid.js and Nextjs set-up

186 views Asked by At

I'm trying to set-up prebid.js ( npm package ) with nextjs projec.

Following example from ( https://www.npmjs.com/package/prebid.js ) by extending webpack config in next.config.js:

let path = require("path")

module.exports = {
  reactStrictMode: true,
  webpack: (config, { buildId, dev, isServer, defaultLoaders, nextRuntime, webpack }) => {

    config.module.rules.push({
      test: /.js$/,
      include: new RegExp(`\\${path.sep}prebid\\.js`),
      use: [
        {
          loader: "babel-loader",
          options: require("prebid.js/.babelrc.js"),
        },
      ],
    })

    return config
  },
}

after this while trying to import prebid.js facing this error:

import {getGlobal} from './prebidGlobal.js';
^^^^^^

SyntaxError: Cannot use import statement outside a module

Same error accurs even without webpack set-up. SO most likely that is incorrect, anyone would know how to set-up this?

versions: Nextjs "12.2.2" React "^17.0.2"

fresh install, no additional libraries.

I can run prebid.js by importing external script. Or using pure react with prebidjs. But doing that with nextjs does not work.

0

There are 0 answers