question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a more explanatory example project

See original GitHub issue

Hi, thanks for your work.

I spent hours trying to customise a property in the list without any success, and I’d like some pointers.

My project uses

  • nest.js
  • typescript
  • adminBro

I’m following the docs to the letter. In the configuration I added:

{ resource: styleModel, options: {
          properties: {
            parentId: {
              components: {
                list: AdminBro.bundle('./components/reference-in-list'),
              },
            }
          }
        } },

My ./components/reference-in-list is defined as the following:

import React from 'react'
import { InputGroup, Label } from '@admin-bro/design-system'
import { BasePropertyProps } from 'admin-bro'

const ReferenceInList: React.FC<BasePropertyProps> = (props) => {
  const { record, property } = props
  const value = record.params[property.name]

  return (
    <InputGroup>
      <Label>{property.name}</Label>
      {value}
    </InputGroup>
    )
}

export default ReferenceInList

All I got is an error:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Is there any special configuration to add when using adminBro with nest.js? There are no docs on your website for using your product with nest.js and the example-app is very basic.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
maxpetersoncommented, Jan 29, 2021

After a bit more investigation I figured out why this wasn’t woking and how to get it to work.

What I originally failed to realise is that AdminBro.bundle expects the uncompiled component (in my case the .tsx file). I will say that again as it is not what I expected:

AdminBro.bundle expects the uncompiled component files

By using component: AdminBro.bundle('./components/company-index') it was finding the files in the dist folder where the tsx has been compiled by nestjs / tsc into js - this resulting js is not compatible with AdminBro.bundle. It is trying to use the version of react from the server not the browser!

By using component: AdminBro.bundle('../../../src/components/company-index') it was finding the files in the src folder where the uncompiled tsx file can be found and can be compiled and bundled byAdminBro.bundle. This is fine on my local dev environment … but not so good on the server (where src does not exist).

To fix this I had to setup nestjs to copy the tsx component files to the dist folder without compiling them, that way AdminBro.bundle can compile them and bundle them up correctly for use in the browser.

Here are the steps I followed to achieve this:

Update nest-cli.json compilerOptions.assets to copy the tsx component files from my admin-panel/components folder in src:

  "compilerOptions": {
    "assets": [
       "admin-panel/components/**"
    ]
  }

Updated tsconfig to exclude src/admin-panel/components (you need do this in tsconfig.build.json tsconfig.json depending on your setup )

 "exclude": [
    "src/admin-panel/components",
  ]

You also don’t need "jsx": "react", in the tsconfig compilerOptions if you are not compiling any tsx files with nestjs,

Finally I updated my AdminBro.bundle paths to be relative (without ../../src as suggested by @SimonB407 - which although it didn’t work I would never have figured this out without this hint so thanks again)

            components: {
              show: AdminBro.bundle('./components/resource-list-link'),
            }

Hope this helps someone else.

1reaction
dklymenkcommented, May 8, 2022

Thanks to @maxpeterson , I resolved the issue I had with user components not being bundled in prod build.

If anyone else is struggling with bundling of custom components in production, you can use my commit here as a reference.

If you’re struggling with nestjs+adminjs setup in general, I guess, you can use my repo for reference too. It’s not very clean and there is only one entity hooked up, but it should clear some things up, if you’re struggling.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Write a Project Description with Examples | Smartsheet
1. Describe the project in a paragraph or two. 2. Why is it necessary? 3. Follow the SMART goal format.
Read more >
How to Write an Explanatory Essay: Topics, Outline, Example
Wonder how to write an explanatory essay? Click for the full guide that contains an explanatory essay example for your help.
Read more >
Explanatory Research | Definition, Guide, & Examples - Scribbr
Explanatory research is a research method that explores why something occurs when limited information is available.
Read more >
How to Write a Project Charter, with Examples [2022] • Asana
Give project stakeholders a clear sense of your main objectives and ... Your project plan builds on your project charter to provide a...
Read more >
Explanatory Research: Types, Examples, Pros & Cons
2. Literature research: Literature research involves examining and reviewing existing academic literature on a topic related to your projects, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found