My project was working 100% fine until I pushed it to Github & cloned it, suddenly I am experiencing a myriad of "Module not found: Can't resolve..." import errors.
Here's 1 example:
Module not found: Can't resolve './components' in '..src\layouts\Main'
Main.js
import { Sidebar, Topbar, Footer } from "./components";
Folder structure
src
├── layouts
│ ├── Main
│ │ ├── components
│ │ ├── Footer
│ │ ├── Footer.js
│ │ ├── Sidebar
│ │ ├── Sidebar.js
│ │ ├── Topbar
│ │ ├── Topbar.js
│ │ ├── Main.js
Update:
How to import redux actions?
src
├── redux
│ │ ├── actions
│ │ ├── dataActions.js
│ │ ├── userActions.js
| | - store.js
| | - types.js
Any help would be greatly appreciated!
You can only import with the component name, when you have an index.js file in the folder Footer.
import { Sidebar, Topbar, Footer } from "./components";
You need to have this folder structurue:
src
├── layouts
│ ├── Main
│ │ ├── components
│ │ ├── Footer
│ │ ├── index.js
│ │ ├── Sidebar
│ │ ├── index.js
│ │ ├── Topbar
│ │ ├── index.js
│ │ ├── Main.js
Updated, because question was updated:
For different redux actions, you can have an index.js file in the actions folder, which does the importing of the actions. Like so:
Within actions create index.js with the actions:
import { dataActions } from './dataActionts'
import { userActions } from './userActions'
Related
Why this work
import ActionButton from './components/atom/ActionButton'
And this not?
export ActionButton from './components/atom/ActionButton'
The line above give me the error:
Cannot find name 'ActionButton'.ts(2304)
My directory structure
.
├── components
│ ├── atom
│ │ ├── ActionButton
│ │ │ ├── ActionButton.spec.tsx
│ │ │ ├── ActionButton.stories.tsx
│ │ │ ├── ActionButton.styles.tsx
│ │ │ ├── ActionButton.tsx
│ │ │ └── index.ts
Where on index.ts I have
export { default } from './ActionButton'
Change it to export { default as ActionButton } from './components/atom/ActionButton' as ActionButton has no named export.
I am working on an application using the MERN stack. The backend and frontend are in the same repository with this hierarchy:
my-project/
├── backend/
│ │
│ .
│ .
│ └── package.json
├── frontend/
│ │
│ .
│ .
│ └── package.json
├── shared/
│ ├── constants/
│ .
│ .
│ ├── index.js
│ └── package.json
├── package.json
└── README.md
I want to have my constants shared between both the backend and frontend. I have the constants in the shared folder/module.
I also want to have any change in the shared package to be reflected in the other packages without needing to reinstall.
What is the best way for both the backend and frontend to use the shared package as a dependency?
You directory structure is almost ok to work with. But there might be some flaws,
my-project/
├── backend/
│ │
│ .
│ .
│ └── package.json
├── frontend/
│ │
│ .
│ .
│ └── package.json
├── shared/
│ ├── constants/
│ .
│ .
│ ├── index.js
│ └── package.json // You might not need this
├── package.json // define shared packages here
└── README.md
For more details, how node
What would be the most optimal structure for a business project with many components, (50 approx)?
That each component has its own module?
src/
├── app
│ ├── app.component.html
│ ├── app.component.scss
│ ├── app.component.ts
│ ├── app.module.ts
│ ├── app-routing.module.ts
│ ├── components
│ │ ├── comp1
│ │ │ ├── comp1.component.ts
│ │ │ ├── comp1.module.ts
│ │ │ └── index.ts
│ │ ├── comp2
│ │ │ ├── comp2.component.ts
│ │ │ ├── comp2.module.ts
│ │ │ └── index.ts
│ │ ├── comp3
│ │ │ ├── comp3.component.ts
│ │ │ ├── comp3.service.ts
│ │ │ ├── comp3.module.ts
│ │ │ └── index.ts
│ ├── views
│ │ ├── admin
│ │ │ ├── admin.module.ts
│ │ │ ├── admin-routing.module.ts
│ │ │ ├── page1 <== Here I show comp1
│ │ │ ├── page2 <== Here I show comp2
│ │ │ ├── page3 <== Here I show comp3
That a module groups all the components? in this case, every time you load the module, will it load all the components in this memory?
src/
├── app
│ ├── app.component.html
│ ├── app.component.scss
│ ├── app.component.ts
│ ├── app.module.ts
│ ├── app-routing.module.ts
│ ├── components
│ │ ├── comp1
│ │ │ ├── comp1.component.ts
│ │ ├── comp2
│ │ │ ├── comp2.component.ts
│ │ ├── comp3
│ │ │ ├── comp3.component.ts
│ │ │ ├── comp3.service.ts
│ │ ├── comps.module.ts <=== // group all components in one module
│ │ ├── index.ts
│ ├── views
│ │ ├── admin
│ │ │ ├── admin.module.ts
│ │ │ ├── admin-routing.module.ts
│ │ │ ├── page1 <== Here I show comp1
│ │ │ ├── page2 <== Here I show comp2
│ │ │ ├── page3 <== Here I show comp3
Any suggestion?
Yes, In angular when you load a module, all of its components are loaded.
You can create feature modules for you different functionalities which you dont want to load at start up. (That is done by lazy loading.)
So the structure will be kind of like this
Core module -> All components required at start up
Featured Modules -> Will load on demand later on.
In angular9, they have provided the feature to lazy load componenets as well. Now you can lazy load components even if the module is loaded.
https://johnpapa.net/angular-9-lazy-loading-components/
There is no strict rule. It depends on the components.
Usually it is a mix. A component that represents a "page" (e.g. the top level routes like your admin area) makes a good module. For "smaller" components used only from a single page it makes sense to put them into the same module.
Other components that are used multiple times from different "page" modules should get into their own module.
The size of the components is also a consideration. The larger a module gets the more it may be good to extract smaller modules.
I have this following project structure.
src/
├── components
│ └── workspace
│ ├── DialogBox.jsx
│ ├── index.js
│ ├── prepareDevNetwork.js
│ ├── ToolBar.jsx
│ └── Workspace.jsx
├── engine
│ ├── service.ts
│ └── index.ts
index.ts -
export { foo } from './service';
service.ts -
export function foo(){/*do something*/}
I'm trying to import foo as follows
import { foo } from '../../engine'
I'am getting unable to resolve path to module ../../engine
I am trying to work out the best directory structure for a small Dojo application (it's a basic booking system).
I am just about finished writing login/registration.
Here is what I have now:
.
├── app
│ ├── client
│ │ ├── JsonRest.js
│ │ ├── lib
│ │ │ ├── defaultSubmit.js
│ │ │ ├── globals.js
│ │ │ ├── globalWidgets.js
│ │ │ ├── Logger.js
│ │ │ └── stores.js
│ │ ├── login.js
│ │ ├── main.css
│ │ ├── main.js
│ │ ├── register.js
│ │ ├── rrl.css
│ │ ├── TODO.txt
│ │ ├── validators.js
│ │ └── widgets
│ │ ├── _AjaxValidatorMixin.js
│ │ ├── AlertBar.js
│ │ ├── AppMainScreen.js
│ │ ├── BusyButton.js
│ │ ├── css
│ │ │ └── AlertBar.css
│ │ ├── Dashboard.js
│ │ ├── LoginForm.js
│ │ ├── RegisterForm.js
│ │ ├── SearchPage.js
│ │ ├── StackFading.js
│ │ ├── _StackFadingMixin.js
│ │ ├── TabFading.js
│ │ ├── templates
│ │ │ ├── LoginForm.html
│ │ │ ├── RetypePassword.html
│ │ │ └── SearchPage.html
│ │ ├── ValidationEmail.js
│ │ ├── ValidationPassword.js
│ │ ├── ValidationUsername.js
│ │ ├── ValidationWorkspace.js
│ └── server
│ ├── AppErrorHandler.js
│ ├── auth.js
│ ├── db.js
│ ├── globals.js
│ ├── node_modules
│ │ ├── express
│ │ ├── jade
│ │ ├── mongodb
│ │ └── mongoose
│ ├── public
│ │ ├── app -> ../../client/
│ │ └── libs -> ../../../libs
│ ├── routes
│ │ └── routes.js
│ ├── server.js
│ ├── test.js
│ └── views
│ ├── index.jade
│ ├── login.jade
│ └── register.jade
├── libs
├── build-report.txt
├── dojo -> dojo-1.7.1
├── dojo-1.7.1
│ ├── app -> ../../app/client
│ ├── dijit
│ ├── dojox
│ ├── dojo
│ └── util
└── dojo-1.8.0
├── app -> ../../app/client
├── dijit
├── dojox
├── dojo
└── util
The idea behind it is that:
the "app" directory will be in a git repository somewhere (it's about time I make one, actually). It has the directories "client" (all the client-side code) and "server" (the node code).
In "libs" I will add things like dgrid, etc. I also noticed that Dojo 1.8 can be loaded within node (!). I will play with this later -- exciting!
Now, here you can see that I basically used symbolic links to make things work.
SERVER side: Under "public", I had symlinks to "app" and "libs". That way, I can access, from HTML, things like /libs/dojo/dojox/form/resources/BusyButton.css, or (important!) /libs/dojo/dojo/dojo.js and /app/main.js (which then instances AppMainScreen with a simple require(["app/widgets/AppMainScreen" ], function( AppMainScreen){ ...
CLIENT side: I have a symlink to the latest Dojo (my boilerplate still has a problem with Dojo 1.8, so I am still using 1.7 for now). However, in order to make this work within the app:
require(["app/widgets/AppMainScreen" ], function( AppMainScreen){
I have a symlink to "app" within Dojo.
Now: I realise the basics (I think the symlink to "app" within Dojo is solved by simply using DojoConfig, for example). But... well, this is my current 100% unoptimised, never built tree.
I can ask you guys give me the tick of approval for this tree? Will it work once I start "building" things? (I am still miles away from doing it, but I will eventually otherwise my [pregnant] wife will go crazy!). Avoiding that symlink to "app" is one of the things I think I should do (but then again, do I need to?).
Thank you!
Merc.
While not being a fan (nor knowledgable at all) of node, it looks to me as there's a huuge javascript library :)
I'd suggest You should really consider making a buildprofile and use the prefix key to set the location of your scripts. As result of a build, you would automatically get an 'app' folder coexisting with dojo,dijit,dojox.
Actually, i would suggest that once there is a separate repository for your dojo application layer, simply do the checkout within the SDK root, e.g. :
wget download.dojotoolkit.org/dojotoolkit-1.7.2-src.tar.gz -O djsrc.tar.gz && tar xfz djsrc.tar.gz && rm djsrc.tar.gz
cd dojotoolkit-1.7.2-src/
svn checkout http://example/mylibrary app
sh utils/buildscripts/build.sh --profile app/package.profile --release /var/nodejs/docroot/lib/
There is no harm at all in developing your app.widgets somewhere else then in your main document root (/lib). You could simply setup one global variable that tells loader where to look.
If built, nothing should be nescessary, but as far as your current tree goes, try something like this
<script>
var isDevelopement = true;
var dojoConfig = {
packages : (isDevelopement) ? [ name: 'app', location: '/app/client/' ] : []
}
</script>