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

How can I import 'antd' or any other lib ? #1278

Closed
justb opened this issue Feb 18, 2019 · 21 comments
Closed

How can I import 'antd' or any other lib ? #1278

justb opened this issue Feb 18, 2019 · 21 comments

Comments

@justb
Copy link

justb commented Feb 18, 2019

Version
9.0.0-beta4

Current behavior
image

To reproduce
image

Expected behavior
I can use antd Button in ButtonGroup

@sapegin
Copy link
Member

sapegin commented Feb 20, 2019

The code on the screenshots is different and the error message may explain what's wrong.

@robertaird
Copy link

robertaird commented Feb 21, 2019

I'm having this same issue in version 9.0.0. I can't seem to import other components into examples, or anything from node_modules. The acorn error is thrown on all components, whether it renders successfully or not. Same thing if I try require instead of import.
screen shot 2019-02-21 at 10 05 34 am
screen shot 2019-02-21 at 10 05 25 am
screen shot 2019-02-21 at 10 05 04 am

Update, it's hack-y but I got it to work by importing things twice in two different code blocks:
screen shot 2019-02-21 at 11 00 01 am

@af
Copy link

af commented Feb 21, 2019

I'm having the same issue as @robertaird when trying to upgrade from v8.0.6 to v9.0.0. Any import statement in my example (jsx inside a markdown file) results in this error being rendered in the browser:

Error: import or require() statements can be added only by editing a Markdown example file: $importName

(here $importName is a placeholder for whatever I tried to import). There is also an error in the console whenever this happens, screenshot below with the full traceback:

screen shot 2019-02-21 at 10 34 47 am

Note: His "double import" trick also works for me but I'm hoping not to need that, for obvious reasons :)

@ibrambe
Copy link

ibrambe commented Feb 21, 2019

Similar issue here with v9.0.0:

styleguide.config.js

module.exports = {
  moduleAliases: {
    '@mycompany/react-components': path.resolve(__dirname, 'src/components')
  }
};

AppBar.md

 `` `jsx noeditor
import { Text } from '@mycompany/react-components';

<AppBar>
  <Text>
    Title
  </Text>
</AppBar>;
`` `

Error:
Error: import or require() statements can be added only by editing a Markdown example file: @mycompany/react-components

@robertaird
Copy link

I tried tracking down what was happening (under the assumption that I was doing it wrong) but I didn't have much luck. By the time the example hits this file, none of the imported filepaths are present in the 'requireMap' object. It seems like Acorn is choking on the jsx the first time around, for some reason, causing the imports in the md files to be missed by webpack(?).

@gwuhaolin
Copy link

gwuhaolin commented Feb 23, 2019

I debug react-styleguidist@9.0.1 and find this issuse cause by acorn getAst fail in react-styleguidist/lib/loaders/utils/getImports.js:
image
acorn think this position has SyntaxError: Unexpected token (6:14)
image

@sheldonHua
Copy link

sheldonHua commented Feb 27, 2019

Has anyone solve this problem? I'm also getting the error:

Error: import or require() statements can be added only by editing a Markdown example file:

When I try to import other components into the markdown file.

@santaclauze
Copy link

Confirmed. @robertaird 's super hack works. But as expressed, it is a bit 'harcore'.

Any followup on this? It seems to be quite a recurrent problem.

@timsnadden
Copy link
Contributor

I have had success fixing this problem by deleting yarn.lock (or package-lock.json for npm users) and reinstalling. I'm not sure what the cause was but one of the dependencies, perhaps transitive, is updated to fix this issue

@kopax
Copy link
Collaborator

kopax commented Mar 7, 2019

@timsnadden how can deleting the lock file can help solving the import issue?

I am also investigating and we dowgraded to v8.0.6 our documentation because of that. Can somebody help me point to the commint that changed the behavior in react-styleguidist? I can't find what change between v8 and v9

@kopax
Copy link
Collaborator

kopax commented Mar 9, 2019

/cc @sapegin 👍

#1310 (comment)

I think timsnadden got the cause, I have a similar case, can we get your opinion about it? I think you have a clue for us. We will get the reason and the fix.

@sapegin
Copy link
Member

sapegin commented Mar 10, 2019

Maybe try to upgrade Buble and Acorn, if the problem is related to one of them. Though there's a problem with Buble — bublejs/buble#171, the fix wasn't yet released.

@kopax
Copy link
Collaborator

kopax commented Mar 11, 2019

I have found a way without yarn:

Add to your dev dependencies:

+    "acorn": "^6.0.2",
+    "acorn-jsx": "^5.0.0",

Rerun npm install and it should be working.

kopax pushed a commit to rollup-umd/documentation that referenced this issue Mar 11, 2019
Due to styleguidist/react-styleguidist#1278 , we had to set in
dependencies acorn@6.0.2 and acorn-jsx@5.0.0 due to peer dependency issue with npm

BREAKING CHANGE: CodeMirror context is unique per example, see
https://github.com/styleguidist/react-styleguidist/releases/tag/v9.0.0 for more info

BREAKING CHANGE: We do not need to list react-styleguidist in our
dependency
@shenshanyoumu
Copy link

I have found a way without yarn:

Add to your dev dependencies:

+    "acorn": "^6.0.2",
+    "acorn-jsx": "^5.0.0",

Rerun npm install and it should be working.

it works for me,thanks

@EvHaus
Copy link

EvHaus commented Mar 14, 2019

For me, doing a full clean re-install helped. ie:

rm -rf yarn.lock node_modules
yarn install

Seems like something in the dependencies is indeed the culprit here.

@paibamboo
Copy link

paibamboo commented Mar 22, 2019

@kopax

@timsnadden how can deleting the lock file can help solving the import issue?

I think this might be the same problem of npm + webpack + acorn. See this comment

@kopax
Copy link
Collaborator

kopax commented Mar 22, 2019

@paibamboo fixing version solved the issue for the moment. And yes it's related with npm+acorn, not sure how webpack is related.

@stale
Copy link

stale bot commented Aug 2, 2019

😴 This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week without any further activity. Consider opening a pull request if you still have this issue or want this feature.

@roblevintennis
Copy link
Contributor

Fwiw, I tried the removal of packages and reinstall without success. The acorn tip did work though:
yarn add --dev acorn acorn-jsx

@elstr
Copy link

elstr commented Oct 8, 2019

Fwiw, I tried the removal of packages and reinstall without success. The acorn tip did work though:
yarn add --dev acorn acorn-jsx

If this doesn't work try rm -rf node_modules && npm install --legacy-bundling

@JustFly1984
Copy link

for me solution was to add

"resolutions": {
    "acorn": "6.4.0"
  }

to package.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests