-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Activestorage npm import causes File Not Found error. #34586
Comments
Causes it when? In a browser? When building with webpack or some other tool? |
Here is my full package.json
|
Thanks, but that's not a reproducible test case. I can't run any of those commands without actual files to build. |
My guess is you're trying to build activestorage for node, which does not have a |
Thanks @javan, you just offered a very good insight. But I will definitively try out UMD build. In the mean time, this issue is still not resolved. to reproduce, setup a nextjs application and include activestorage using yarn. The error would definately popup, especially when are using a custom node server. |
No UMD build anywhere. |
The issue isn't bundling with nodejs, it's running
rails/activestorage/rollup.config.js Lines 17 to 20 in 41e468a
Runkit is a nodejs environment so, same issue. I've confirmed that the code example you provided works fine in the browser: import { DirectUpload } from 'activestorage'; 👇 https://glitch.com/edit/#!/sour-geese?path=src/index.js:1:0 👇 |
I'm having same issue when I'm trying to import the the only problem to make this code compile in server side is to move the cons fileSlice definition to a function, so we'll defer it's initialization
but this will work
So I kinda copy this file to my project and updated to use this syntax. Hope it helps anyone |
If anyone is trying to get activestorage working with server side rendering, you can do the following: create a file activestorageStub.js (or ts) that has the following line: export const DirectUpload = null; then in webpack, add it as an alias: const path = require('path');
if (ssr) {
resolve.alias = {
activestorage: path.resolve(PATH, TO, FILE, 'activestorageStub.js'),
}
} |
@AdnanTheExcellent can you share your webpack config in whole? kind of new to running custom nextjs webpack |
For TS tsconfig.json
path/to/custom/activestorage.js
declare module
import
|
Hi, I just have come across this because I am refacturing my app from vanilla React to Next.JS. I found a very easy way to deal with this problem by using the dynamic import feature from Next.js with the option ssr: false. So I import DirectUpload (in my Case I use DirectUploadProvider) like this:
And change the Component Name in the code to "DirectUploadProviderNoSSR" accordingly. Also see the Next.JS docs here. Andreas |
Actual behavior
import { DirectUpload } from 'activestorage';
causes this error
System configuration
React config:
The text was updated successfully, but these errors were encountered: