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.

Declaration files cannot be found when consuming nested input files

See original GitHub issue

Hi, my rollup config looks like this:

import typescript from 'rollup-plugin-typescript2'
import rebasePlugin from 'rollup-plugin-rebase'
import pkg from './package.json'

export default {
  // Entry files
  input: {
    index: 'src/index.ts',
    Button: 'src/Button/index.ts',
    Spinner: 'src/Spinner/index.ts',
    Icon: 'src/Icon/index.ts',
    Note: 'src/Note/index.ts',
    Logo: 'src/Logo/index.ts',
    Card: 'src/Card/index.ts',
    Image: 'src/Image/index.ts',
    Modal: 'src/Modal/index.ts',
    Drawer: 'src/Drawer/index.ts',
    Tabs: 'src/Tabs/index.ts',
    Accordion: 'src/Accordion/index.ts',
    List: 'src/List/index.ts',
    Form: 'src/Form/index.ts',
    Transition: 'src/Transition/index.ts',
    Divider: 'src/Divider/index.ts',
    NewsletterForm: 'src/NewsletterForm/index.ts',

    // Layout
    Grid: 'src/Layout/Grid/index.ts',
    Container: 'src/Layout/Container/index.ts',

    // FormControls
    TextInput: 'src/FormControls/TextInput/index.ts',
    TextArea: 'src/FormControls/TextArea/index.ts',
    Select: 'src/FormControls/Select/index.ts',
    Stepper: 'src/FormControls/Stepper/index.ts',
    Checkbox: 'src/FormControls/Checkbox/index.ts',
    Radio: 'src/FormControls/Radio/index.ts',
    Toggle: 'src/FormControls/Toggle/index.ts',

    // Type
    P: 'src/Type/P/index.ts',
    H1: 'src/Type/H1/index.ts',
    H2: 'src/Type/H2/index.ts',
    H3: 'src/Type/H3/index.ts',
    H4: 'src/Type/H4/index.ts',
    Ol: 'src/Type/Ol/index.ts',
    Ul: 'src/Type/Ul/index.ts',
    Code: 'src/Type/Code/index.ts',
  },

  // Output as pure es modules into a lib folder, should probably add more output types at some point
  output: [
    {
      dir: 'lib',
      format: 'es',
    },
  ],
  // Exclude any dependancies in the bundle, these will auto install when the users adds this lib
  // Exclude any peerDepenacies, the consumer should install these themselves
  external: [
    ...Object.keys(pkg.dependencies || {}),
    ...Object.keys(pkg.peerDependencies || {}),
  ],
  plugins: [
    // Handle typescript
    typescript({
      typescript: require('typescript'),
      exclude: ['**/*.stories.tsx', 'node_modules'],
    }),
    // Handle all assets
    rebasePlugin(),
  ],
}

When consuming my package, importing components with the following syntax works fine:

import { Button } from '@mycomponents'

I have added multiple inputs for people to consume just the component they want. I have noticed that when consuming, this is working for all of my components except the nested ones. (eg all the inputs live in a folder called FormControls)

Works: import { Button } from '@mycomponents/lib/Button' Doesn’t work: import { TextInput } from '@mycomponents/lib/TextInput'

Is there a recommended way to do this?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ezolenkocommented, Feb 24, 2020

Dropping them into a flat file structure is not feasible because they might have name conflicts, also typescript generates internal imports based on file structure…

You could merge them into a single file. There are some tools that can take d.ts and merge them, or you could run tsc explicitly and use bundling options.

1reaction
sami616commented, Feb 24, 2020

Is there anyway to dump all of the d.ts files into one dir instead of recreating the project folder structure?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not find a declaration file for module - Stack Overflow
I have burnt on this when I try to consume a package with "main": "index" in systemjs . – unional. Mar 22, 2017...
Read more >
@rollup/plugin-typescript - npm
file Rollup configuration, and TypeScript to output declaration files, users may encounter a situation where the declarations are nested ...
Read more >
input can't find file (nested directory structure) - TeX
I'd like to input it into content/chapter2.tex . However when I use \input{./figures/LaTeX/figure} it tells me it can't find the file even ...
Read more >
Documentation - Namespaces - TypeScript
Even though the files are separate, they can each contribute to the same namespace and can be consumed as if they were all...
Read more >
Learn Modules In Azure Bicep - Basics To Advanced, How It ...
Any Bicep file can be consumed as a module; In other words, module is about how you consume a Bicep file, not how...
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