jxnblk / mdx-go

:zap: Lightning fast MDX-based dev server for progressive documentation
https://mdx-go.now.sh
MIT License
364 stars 27 forks source link

Failed to compile, unexpected character '#' #19

Open karanrajpal14 opened 6 years ago

karanrajpal14 commented 6 years ago

I've been trying to get this to work for a while now but, unfortunately, I haven't had the luck. Firstly, the directory structure looks like this:

├── docs
│   └── res.mdx
├── node_modules
│   ├── bloomer
│   ├── classnames
│   └── tslib
├── package.json
└── package-lock.json

I cd to this directory and run mdx-go docs and get the following error:

➜ mdx-go docs 
[mdx-go] starting dev server...
✔ success [mdx-go] compiled in 1s 848ms

 ERROR  Failed to compile with 1 errors                                 19:30:57

 error  in /home/karan/.nvm/versions/node/v8.11.4/lib/node_modules/mdx-go/lib/client/keyboard-shortcuts.md

Module parse failed: Unexpected character '#' (2:0)
You may need an appropriate loader to handle this file type.
| 
> ### Keyboard Shortcuts
| 
| - `/`: Show directory listing

 @ /home/karan/.nvm/versions/node/v8.11.4/lib/node_modules/mdx-go/lib/client/routes.js 11:0-56 44:26-43
 @ /home/karan/.nvm/versions/node/v8.11.4/lib/node_modules/mdx-go/lib/client/App.js
 @ /home/karan/.nvm/versions/node/v8.11.4/lib/node_modules/mdx-go/lib/client/index.js
 @ multi webpack-hot-middleware/client /home/karan/.nvm/versions/node/v8.11.4/lib/node_modules/mdx-go/lib/client/index.js

✖ 「wdm」: 
ERROR in ./client/keyboard-shortcuts.md 2:0
Module parse failed: Unexpected character '#' (2:0)
You may need an appropriate loader to handle this file type.
| 
> ### Keyboard Shortcuts
| 
| - `/`: Show directory listing
 @ ./client/routes.js 11:0-56 44:26-43
 @ ./client/App.js
 @ ./client/index.js
 @ multi webpack-hot-middleware/client ./client/index.js
[mdx-go] listening on http://localhost:8080
^C

Any idea why it's breaking due to a file that isn't even present in the directory? Is there something wrong on my end that I need to change? Please do let me know.

jxnblk commented 6 years ago

Thanks! That's definitely a bug. I think I have a fix in #20 if you wanna try installing the latest version

karanrajpal14 commented 6 years ago

Hey thanks for attempting to fix it! I do think the issue is resolved for the case I specified but there is one other case I would like to mention and highlight another issue I am facing.

The mdx file does seem to be compiling but, I do not see any content on the page right now. I just have # Hello in the index.mdx file right now.

I only see a blank page with the following error in the console

Uncaught TypeError: Cannot read property 'Root' of undefined
    at eval (routes.js:126)
    at Module../client/routes.js (main.js:1876)
    at __webpack_require__ (main.js:768)
    at fn (main.js:131)
    at eval (App.js:11)
    at Module../client/App.js (main.js:1756)
    at __webpack_require__ (main.js:768)
    at fn (main.js:131)
    at eval (index.js:8)
    at Module../client/index.js (main.js:1840)

Any idea what's going on here?

Also, the second case that I mentioned. Is it necessary to have the mdx files inside another folder? In my case, I will most likely need just one mdx file and some components from BloomerJS. If I do place the index.mdx file in the root directory, it picks up the README.md files from the node_modules directory and errors out. What do you think? It's not a big deal but just something to consider if you've got the time.

jxnblk commented 6 years ago

Glad that the original issue was resolved. For your second question, mdx-go uses webpack's require.context to pick up all files that end in .js, .md or .mdx, so it's recommended you use it on a folder that doesn't contain node_modules. I'm looking into other ways to specify which files it picks up, but for now I'd recommend making a separate docs folder or similar

karanrajpal14 commented 6 years ago

Ah! That makes sense. I'll stick to the recommended structure if that's the case. Any idea what's the issue with rendering the mdx though? That error does not seem to be going away irrespective of what I do and I always see a blank page and nothing more.

airtonix commented 5 years ago
airtonix commented 5 years ago

ok so you must have a docs/index.md or docs/index.mdx... you can not simply have only docs/readme.md, or just docs/README.md

talentlessguy commented 4 years ago

The issue keeps happening:

 WAIT  Compiling...                             3:36:46 PM

✔ success [mdx-go] compiled in 195ms

 ERROR  Failed to compile with 1 errors         3:36:47 PM

 error  in /home/v1rtl/.local/pnpm/pnpm-global/3/node_modules/.pnpm/registry.npmjs.org/mdx-go/2.0.0-32/node_modules/mdx-go/lib/client/keyboard-shortcuts.md

Module parse failed: Unexpected character '#' (2:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| 
> ### Keyboard Shortcuts
| 
| - `/`: Show directory listing