Skip to content
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

Nextjs v11 with webpack5 doesn't work in dev mode #224

Closed
SimonVillage opened this issue May 1, 2021 · 19 comments · Fixed by #276
Closed

Nextjs v11 with webpack5 doesn't work in dev mode #224

SimonVillage opened this issue May 1, 2021 · 19 comments · Fixed by #276
Labels
bug Something isn't working

Comments

@SimonVillage
Copy link

I followed this tutorial: https://github.com/tradingview/charting-library-examples/tree/master/nextjs-javascript

When using npm run build and npm run start it works without problems. However, when using npm run dev tradingview isn't showing.

@timocov
Copy link
Contributor

timocov commented May 3, 2021

I just opened and it seems that it works fine:

image

Can you please share what exact steps you did?

@mkromann
Copy link

mkromann commented May 26, 2021

I experienced the same issue.

But this is related to the newest versions of Next.js which defaults to Webpack 5. It will work if you revert to Webpack 4:

module.exports = {
   future: {
      webpack5: false,
   },
};

@Tokenspec
Copy link

The problem is repeated at random whenever I'm installing a new package and I'm force to override the node modules folder with a working copy every time this happens, does anyone have a fix? changing the next.config.js did not work for me.

@mnkhod
Copy link

mnkhod commented Jun 26, 2021

is anyone working on making the chart compatible with webpack 5?

@tlrjs
Copy link

tlrjs commented Aug 30, 2021

I am using Next.js v 11.1 and the trading view charts also aren't rendering in dev mode. After doing a yarn build and deploying to production they show.

This didn't use to be an issue on Next.js 9.
Screen Shot 2021-08-30 at 2 06 33 PM

My guess is it's a problem with webpack 5 though. Previous versions of Next used webpack 4.

@tlrjs
Copy link

tlrjs commented Sep 2, 2021

I just opened and it seems that it works fine:

image

Can you please share what exact steps you did?

Can you try with Next.js 11 and let us know if it's working for you?

@timocov timocov changed the title nextjs tradingview not rendering in dev mode Nextjs v11 with webpack5 doesn't work in dev mode Sep 3, 2021
@edew
Copy link
Contributor

edew commented Sep 6, 2021

It looks like this is a bug with Next.js/Webpack and resolving ESM files. I have created a minimal reproduction here https://github.com/edew/nextjs-webpack-module-bug.

Until this is fixed in Next.js you can try one of these workarounds:

  1. Revert to Webpack 4, or
  2. Try deleting the "type": "module" line in Charting Library's package.json to force Webpack to resolve the file as a CommonJS module https://github.com/tradingview/charting_library/blob/master/charting_library/package.json#L4

vercel/next.js#23498 (comment)

@asharimh97
Copy link

It looks like this is a bug with Next.js/Webpack and resolving ESM files. I have created a minimal reproduction here https://github.com/edew/nextjs-webpack-module-bug.

Until this is fixed in Next.js you can try one of these workarounds:

  1. Revert to Webpack 4, or
  2. Try deleting the "type": "module" line in Charting Library's package.json to force Webpack to resolve the file as a CommonJS module https://github.com/tradingview/charting_library/blob/master/charting_library/package.json#L4

I tried this, it works when I revert the webpack to v4, but I have another module that only works when I use the webpack 5. So I tried another workaround, but after I deleted the type: "module" while using webpack 5 the chart won't show up.

*PS: I use NextJS 10

@rahulsuresh-git
Copy link

Any update on this issue? Nextjs 12 doesn't support going back to webpack 4 anymore.
So the only way out is to drop to Nextjs 11. Does anyone have a workaround?

@timocov
Copy link
Contributor

timocov commented Jan 18, 2022

@icy-meteor why are you asking to provide a fix here? For me it looks like an issue of next.js as we found out in #224 (comment). Maybe you would like to create an issue in nextjs repo and fix it there? Alternatively you still have the second option, have you tried it?

@rahulsuresh-git
Copy link

@icy-meteor why are you asking to provide a fix here? For me it looks like an issue of next.js as we found out in #224 (comment). Maybe you would like to create an issue in nextjs repo and fix it there? Alternatively you still have the second option, have you tried it?

Hey, thanks for the reply.
I had tried the second method first but ran into a lot of errors. Then I tried the first method, and I seemed to get it working at the cost of downgrading several other packages as well that were dependant on Next.js 12 or webpack 5.
Now I upgraded all my packages to latest version and tried method 2 again, and it seems to work perfectly with Next.js 12 and webpack 5.
Just took a while to tinker around and hit the right configuration to get it working! Thanks for your help @timocov 💯

Appreciate it :)

@matthewlilley
Copy link

@timocov this is still an issue with both solutions given and Next.js 12, which is unfortunately not allowing us to make use of this library despite paying. Are you unable to distribute this in a normal fashion via NPM?

@timocov
Copy link
Contributor

timocov commented Jan 25, 2022

Unfortunately we're unable to publish charting library as a npm package so far.

We'll try to fix the issue caused by esm and will go back as far as we get anything.

@timocov timocov added the bug Something isn't working label Jan 25, 2022
@skedzior
Copy link

skedzior commented Feb 9, 2022

has anyone tried using dynamic imports?

import dynamic from 'next/dynamic';

const TradingViewChart = dynamic(() => import('../components/charts/TradingViewChart'), {
  ssr: false
});

@romfrancois romfrancois mentioned this issue Feb 18, 2022
2 tasks
@timocov
Copy link
Contributor

timocov commented Feb 18, 2022

It seems the issue has been fixed by nextjs team and now it works with the latest nextjs version. Please check it out and say if it doesn't work for you.

@thukuyoma
Copy link

@timocov I am still having the same issue I use nextjs11.1.2 and if I use webpack 5 I get this error module is not defined ReferenceError: module is not defined at Module../public/static/charting_library/charting_library.esm.js (http://localhost:3000/_next/static/chunks/src_components_spot-trading_TVChartContainer_index_tsx.js:839:30) at Module.options.factory (http://localhost:3000/_next/static/chunks/webpack.js?ts=1645630009449:677:31) at __webpack_require__ (http://localhost:3000/_next/static/chunks/webpack.js?ts=1645630009449:29:33) at fn (http://localhost:3000/_next/static/chunks/webpack.js?ts=1645630009449:346:21) at Module../src/components/spot-trading/TVChartContainer/index.tsx (http://localhost:3000/_next/static/chunks/src_components_spot-trading_TVChartContainer_index_tsx.js:23:89) at Module.options.factory (http://localhost:3000/_next/static/chunks/webpack.js?ts=1645630009449:677:31) at __webpack_require__ (http://localhost:3000/_next/static/chunks/webpack.js?ts=1645630009449:29:33) at Function.fn (http://localhost:3000/_next/static/chunks/webpack.js?ts=1645630009449:346:21)

@timocov
Copy link
Contributor

timocov commented Feb 23, 2022

@tukuyoma It is not supposed to work with v11. The minimal nextjs version that works is 12.1.0.

@thukuyoma
Copy link

@timocov thanks it worked

@achepukov
Copy link

Upgrade nextjs to v 12.1 fix the issue for me as well! Thanks a lot, I spent 3 days to figure it out!

@timocov timocov pinned this issue Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.