-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
DOCS: How to use in SSR context #543
Comments
It seems that rollup doesn't understand that it's module 🤔. Can you please create repro for that? |
It is a private library... I could not share this access 😔. Do you require something specific about the implementation? |
The error is there for webpack as well. I've tried adding |
Steps to reproduce:
|
My problem also occurs in a next-js application, I suspect it is due to a babel configuration but I cannot identify which one, this error also occurs when executing the unit tests with jest. @timocov Do you know what the configuration could be? I understand that you use typescript, I suppose that when transpiling the code we have a configuration that we need to have in our babel. |
Ah, it seems that I understand what's going on here. That's because you're trying to import that module in nodejs environment, which requires either commonjs or esmodules (mjs and full path with extension). You can try to import standalone version in nodejs (it doesn't have any import and is just iife). Maybe @NekitCorp or @azhang can help here? |
Yea, agreed with @timocov. Looks like it's not parsing the import statement correctly because it's not the full path including .js extension. Otherwise i'm not sure - not familiar with Next.js and webpack does seem to support es6 modules natively |
Ok, this can be worked around with a dynamic import in next. As mentioned by @NekitCorp here libraries don't usually throw fatal errors when they're imported in the SSR context, so that might be worth fixing. Thanks for the library and all your hard work. It's absolutely fantastic! |
I think we need to add article in the docs for that (how to integrate in SSR context). |
Any idea on how this could be remedied in a Nuxt context? (#557 ) |
@miketeix lightweight-charts cannot be instantiated in SSR context (because it creates canvases and all work is done with them). Do Nuxt have somrthing like dynamic loading? If so, I think you can use it to load library via it. |
Hey thanks the tip @timocov, it worked for me by loading third-party script using |
@timocov As it seems to me, need to make another version of the library for Now at
but in
which leads to the errors described above. Example
|
@NekitCorp what's purpose of importing the library directly on nodejs side? I hadn't a deal with SSR so I'm not quite know how exactly SSR on nodejs works. I agree that there is some issue with the library's
The question is - who expects and needs commonjs version of the library? Afaik all bundlers support and welcome esm version over cjs one. It looks like the library shouldn't be imported directly in nodejs context at all, isn't it? Just wondering what's the best solution here might be... |
I'm running into this running tests w/ jest which does run on node right? I ended up just ignoring it for now (as in https://stackoverflow.com/a/66340153/4200039) but at some point I would like to load this and run tests against it |
Svelete REPL for one. I'm running into this problem with bundler.js/unpkg.com and getting 'Error: Cannot find "/coordinate-space" in fancy-canvas@1.0.0' when using the following imports :
Not sure how Fiddle links on the demo page work, does they do successfully complete the import.... |
I imported the component that create my chart this way, so it worked. |
@raulvictorrosa Hey, can you please share how this can be fixed for Next.js? I've tried with dunamic import, doesn't work. Here is the example with dynamic + lightweight-charts+next.js which simply doesn't work! :( https://codesandbox.io/s/withered-meadow-2cvtn?file=/pages/index.jsx |
Actually I did the same way as in your link but for me just worked in the development env, but when I try to build the app the error happens again in the build process. |
Found here the solution bro, actually I put this way, disabling the SSR, so this way worked in the build process and in dev env.
|
This works btw |
For the people who use
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {...};
const withTM = require('next-transpile-modules')(['lightweight-charts', 'fancy-canvas']);
module.exports = withTM(nextConfig); If you are using next 13.1 and later, please check #543 (comment) out. |
for astro you just need to do |
SOLVED: using the implementation from @mustaphaturhan helped. i tried everything but that. thank you Hi, I still get the same error as above in NextJS and react. I am trying to create a component and I build the component as I do from above even using dynamic load, but the problem comes from the lightweight library itself To reiterate, without even importing this component anywhere, I get thrown this error, so the dynamic code isn't solving anything while this component just renders by itself.
Here's my code: The error occurs at the MainChart Component
|
using the latest next.js version 13.1 you can now solve this with editing the next.config.js in the following way: module.exports = {
transpilePackages: ['lightweight-charts']
} more info here in the release notes of 13.1 |
Lightweight Charts Version: 3.1.3
Steps/code to reproduce:
Encapsulating lightweight-charts in an external library.
Actual behavior:
I have my own library which encapsulates lightweight-charts and when installing it generates this error, I am using rollup to compress the files with a cjs format I cannot understand the conflict.
Expected behavior:
Module should be found.
I don't know what I am missing
Screenshots:
Error
Rollup config
The text was updated successfully, but these errors were encountered: