Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to run the create-react-app example #365

Closed
tornordqvist opened this issue Dec 22, 2018 · 19 comments · Fixed by #1422
Closed

Error when trying to run the create-react-app example #365

tornordqvist opened this issue Dec 22, 2018 · 19 comments · Fixed by #1422
Labels
📚 area/docs This affects documentation

Comments

@tornordqvist
Copy link

Subject of the issue

I get an error when trying to run the create-react-app example.

Your environment

Windows 10
Node v10.14.0
NPM 6.4.1

Steps to reproduce

Easy. I do:
git clone
cd mdx/examples/create-react-app
npm i
npm start

Expected behaviour

The app should run without errors.

Actual behaviour

I get this error when running the app;

Failed to compile
./src/App.js
Module not found: You attempted to import C:\Repos\mdx\examples\create-react-app\node_modules\.cache\mdx.macro\Content.796904d8db.mdx.js which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
@tornordqvist
Copy link
Author

The mdx.macro should read the Content file from /src but seems to look locally in the node_modules/.cache/mdx.macro folder.

@briedel1
Copy link

briedel1 commented Jan 9, 2019

I am seeing the same behavior. Did you have any luck?

@briedel1
Copy link

briedel1 commented Jan 9, 2019

I ejected and used the nom package @mdx-js/loader. The CRA docs should be updated to mention that they don't currently work with mdx.macro.

@KeziahMoselle
Copy link

I got this error, any fix planned without ejecting ?

@johno
Copy link
Member

johno commented Mar 18, 2019

My guess is it's this line in mdx.macro that doesn't work with Windows environments.

@freaksauce
Copy link

I am experiencing the same issue on macOS 10.14.3 so it's not a Windows issue. I tried setting up a new CRA app using the latest mdx package with a simple import - issue raised for mdx.macro

@devuxer
Copy link

devuxer commented Dec 5, 2019

I'm getting this error on Windows with a pristine CRA --typescript project.

@aress31
Copy link

aress31 commented May 17, 2020

Getting this issue then on a newly created project following the doc - my env is Windows.

@nicobrinkkemper
Copy link

nicobrinkkemper commented Jun 14, 2020

I don't understand why this issue is still open since Dec 22, 2018.

var _jsxFileName = "C:\\Users\\nico\\Documents\\Code\\fourymm\\src\\data\\Welcome.mdx";
import React from 'react';
import { MDXTag } from '@mdx-js/tag';
import 'C:\Users\nico\Documents\Code\fourymm\src\data\Welcome.mdx';

The top line is fine, the bottom line is just plain wrong? This should be a easy fix for a maintainer right? Meanwhile it's stopping everyone trying this out on Windows, following the documented advice to use mdx.macro for create-react-app projects. The above fixes seem either very radical (ejecting) and outdated (using .env file). I'm sorry for sounding harsh, maybe I'm missing something? Please help me understand

Edit: just to add to the pool of solution. Using WSL can solve this problem. It's a bit slower, and even more so if you keep the folder where it is, so I suggest moving the folder to the WSL home directory.

@wooorm
Copy link
Member

wooorm commented Nov 13, 2020

mdx.macro is not maintained here. There is a stalled PR (#589) to change the suggestion in this example. As for “why is this still a problem”, well, the usual: oss, priorities, real life, etc etc etc.

If someone wants to work on a PR to change the docs, that would be greatly appreciated

@ChristianMurphy ChristianMurphy added good first issue 👋 This may be a great place to get started! help wanted 🙏 This could use your insight or help 📚 area/docs This affects documentation labels Dec 16, 2020
@thediveo
Copy link

This PR example doesn't work for me when applied to my cra project:

Unexpected '!' in '!babel-loader!mdx-loader!./About.mdx'. Do not use import syntax to configure webpack loaders  import/no-webpack-loader-syntax

@ChristianMurphy
Copy link
Member

@thediveo that is a lint warning, not a webpack error.
So it may be, and probably is, working?

@thediveo
Copy link

Using "// eslint-disable-next-line import/no-webpack-loader-syntax" immediately before the import now results in "Cannot find module '!babel-loader!mdx-loader!./About.mdx' or its corresponding type declarations.ts(2307)"

@ChristianMurphy
Copy link
Member

ChristianMurphy commented Dec 16, 2020

@thediveo I can't speak the the specifics how you have your TSConfig setup, but it can work with webpack and typescript .
Here's an example, based on CRA, to start with https://codesandbox.io/s/busy-resonance-lpuvf

@thediveo

This comment has been minimized.

@ChristianMurphy

This comment has been minimized.

@thediveo

This comment has been minimized.

@ChristianMurphy

This comment has been minimized.

@thediveo
Copy link

@ChristianMurphy thank you very much, will try mdx2 and as a fallback I can always rename the affected .tsx module to .jsx to work around the typescript error.

wooorm added a commit that referenced this issue Dec 28, 2020
Create React App is the most looked at resource by users here on GitHub.
But it’s suggesting an old, unmaintained, and buggy way to use MDX.

This instead updates the guide to use our maintained projects, without
having to eject from CRA.

As CRA itself is an ever-changing “init” tool, which can support MDX by
following a couple steps, I don’t think it’s wise to have an example in
the project: we want folks to do `npx create-react-app ...`, not clone
our custom example.

Not having CRA checked in also makes for a faster `yarn install`.

Perhaps developing our own [CRA
template](https://create-react-app.dev/docs/custom-templates) might be
nice for the future, but for now I’ve kept it at an up to date and
working guide.

Related to GH-1015.
Related to GH-1388.

Closes GH-365.
Closes GH-589.
wooorm added a commit that referenced this issue Dec 28, 2020
Create React App is the most looked at resource by users here on GitHub.
But it’s suggesting an old, unmaintained, and buggy way to use MDX.

This instead updates the guide to use our maintained projects, without
having to eject from CRA.

As CRA itself is an ever-changing “init” tool, which can support MDX by
following a couple steps, I don’t think it’s wise to have an example in
the project: we want folks to do `npx create-react-app ...`, not clone
our custom example.

Not having CRA checked in also makes for a faster `yarn install`.

Perhaps developing our own [CRA
template](https://create-react-app.dev/docs/custom-templates) might be
nice for the future, but for now I’ve kept it at an up to date and
working guide.

Related to GH-1015.
Related to GH-1388.

Closes GH-365.
Closes GH-589.
wooorm added a commit that referenced this issue Dec 29, 2020
Create React App is the most looked at resource by users here on GitHub.
But it’s suggesting an old, unmaintained, and buggy way to use MDX.

This instead updates the guide to use our maintained projects, without
having to eject from CRA.

As CRA itself is an ever-changing “init” tool, which can support MDX by
following a couple steps, I don’t think it’s wise to have an example in
the project: we want folks to do `npx create-react-app ...`, not clone
our custom example.

Not having CRA checked in also makes for a faster `yarn install`.

Perhaps developing our own [CRA
template](https://create-react-app.dev/docs/custom-templates) might be
nice for the future, but for now I’ve kept it at an up to date and
working guide.

Related to GH-1015.
Related to GH-1388.

Closes GH-365.
Closes GH-589.
Closes GH-1422.

Reviewed-by: Christian Murphy <[email protected]>
@wooorm wooorm removed good first issue 👋 This may be a great place to get started! help wanted 🙏 This could use your insight or help labels Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 area/docs This affects documentation
Development

Successfully merging a pull request may close this issue.