Docz: Cannot import README.md in monorepo

Created on 19 Nov 2018  路  5Comments  路  Source: doczjs/docz

Importing and using markdown files as components does not work as expected.

I am using a monorepo, and have set up aliases in the config like so:

const modifyBundlerConfig = config => {
  config.resolve.alias = Object.assign({}, config.resolve.alias, {
    '@core': path.resolve(__dirname, '..', 'core'),
    '@ui': path.resolve(__dirname, '..', 'ui'),
    '@root': path.resolve(__dirname, '../../'),
    '@intl': path.resolve(__dirname, '..', 'intl')
  });

  return config;
};

When I try to import and use a README from the @root of the project:

import Readme from '@root/README.md';

<Readme />

It fails to parse the markdown, giving me the error:

Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
question

Most helpful comment

@pedronauck Thanks for answering! I think that "trying to load content outside docz isn't possible" should have more emphasis in the docs, as I had to search for this issue to find why my documentation couldn't be built.

All 5 comments

This actually occurs for any files outside the directory that Docz is in, not just markdown files but also tsx. It seems it does not work to have docz in its own directory.

We have some files that are ignoring by default on docz:

const ignore = [
  'readme.md',
  'changelog.md',
  'code_of_conduct.md',
  'contributing.md',
  'license.md',
]

But we have an option called ignore as config that you can change the default option:

// doczrc.js
export default {
  ignore: []
}

Try to change this options and see what's happening.

I still have the same problem.

I also have the same problem if I try to import any component from outside the docz package.

The directory structure is like this:

- README.md
- packages
  |-- docs
  |-- ui
  |-- core

docz lives in the docs package. If I try to import the README from the root, or a component from ui, I get the error

Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.

If I move docz to the root, I don't have the issue.

Oh for sure, you're trying to load content outside docz, this isn't possible. Was a decision that we'd some time ago about some architecture and performance issues. I really advise you to put docz on your root directory as a devDependency of your monorepo, I'm doing this in a project from my work and works well.

@pedronauck Thanks for answering! I think that "trying to load content outside docz isn't possible" should have more emphasis in the docs, as I had to search for this issue to find why my documentation couldn't be built.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

koddr picture koddr  路  3Comments

capaj picture capaj  路  3Comments

fenbka picture fenbka  路  3Comments

hayk94 picture hayk94  路  3Comments

w0wka91 picture w0wka91  路  3Comments