0

I need to add the following external css and scripts in my NextJS app (NextJS version 13.4.13).

Style
https://company.com/statics/1/package/dist/1/styles/dls.min.css

Script
https://company.com/statics/1/package/dist/1/scripts/dls.min.js

How can I add it?

I tried the following.

File path: app-name/src/app/layout.js

import 'https://company.com/statics/1/package/dist/1/styles/dls.min.css'
import './globals.css'
import Script from "next/script";


export const metadata = {
  title: 'title',
  description: 'desc',
}

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script type="text/javascript" src="https://company.com/statics/1/package/dist/1/scripts/dls.min.js" />
      </body>
    </html>
  )
}

But it throws error:

Failed to compile:

https://company.com/statics/1/package/dist/1/styles/dls.min.css Module build failed: UnhandledSchemeError: Reading from "https://company.com/statics/1/package/dist/1/styles/dls.min.css" is not handled by plugins (Unhandled scheme). Webpack supports "data:" and "file:" URIs by default. You may need an additional plugin to handle "https:" URIs. Import trace for requested module: https://company.com/statics/1/package/dist/1/styles/dls.min.css ./src/app/layout.js

3
  • could you use <Head> tags from Next and then just use a standard <link> tag in there? Commented Aug 9, 2023 at 11:12
  • @JonahCRowlinson The error is gone but the styles not loading. Believe Head no longer fits for this purpose in NExtJS version 13.4 and above. Commented Aug 9, 2023 at 11:24
  • 1
    ah - seems NextJS docs say to not use a CDN and all external files should be downloaded, as can be seen here, in the Good to know box. Commented Aug 9, 2023 at 11:27

1 Answer 1

1

NextJS suggest not to include CSS from an external CDN, and instead all external files should be downloaded into the project source.

Good to know: External stylesheets must be directly imported from an npm package or downloaded and colocated with your codebase. You cannot use .

Source

Sign up to request clarification or add additional context in comments.

Comments

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.