-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Unexpected token in code example #1321
Comments
I am getting this same error. Everything works fine on version 9.0.4, but get the above error on 9.0.5 for all my components. |
Thank you, downgrading to 9.0.4 fix the problem |
…leguidist BREAKING CHANGE: [email protected] has breaking changes to how examples are loaded, read more here: https://github.com/styleguidist/react-styleguidist/releases/tag/v9.0.0. Also note, react-styleguidist is hard pinned to `9.0.4` due to the following issue: styleguidist/react-styleguidist#1321.
…leguidist BREAKING CHANGE: [email protected] has breaking changes to how examples are loaded, read more here: https://github.com/styleguidist/react-styleguidist/releases/tag/v9.0.0. Also note, react-styleguidist is hard pinned to `9.0.4` due to the following issue: styleguidist/react-styleguidist#1321.
downgrading works, but doesn't seem like a nice solution. what is the underlying issue? |
Having the same issue. Also 9.0.4 gets picked up as having vulnerabilities by npm audit which doesn't make it a super viable alternative. |
It seems that this issue doesn't affect everyone so maybe we can get more info by sharing our configs. Below is ours, we use it with the following libraries (see the full list here):
const fs = require('fs');
const path = require('path');
const fileExistsCaseInsensitive = require('react-styleguidist/lib/scripts/utils/findFileCaseInsensitive');
module.exports = {
assetsDir: 'styleguide',
getExampleFilename(componentPath) {
const parsedPath = path.parse(componentPath);
const parentDirName = parsedPath.dir.split('src/components/')[1] || '';
const parentDirPath = path.join(__dirname, 'styleguide', 'examples', parentDirName);
if (!fs.existsSync(parentDirPath)) {
return false;
}
const examplePath = path.join(parentDirPath, `${parsedPath.name}.md`);
return fileExistsCaseInsensitive(examplePath) || false;
},
pagePerSection: true,
moduleAliases: {
components: path.resolve(__dirname, 'src/components'),
},
sections: [
{
name: 'Atoms',
components: 'src/components/Styled*.js',
description: 'Base design atoms.',
},
{
name: 'UI',
content: 'styleguide/pages/UI.md',
components: 'src/components/*.js',
ignore: ['src/components/Contribute*.js', 'src/components/Styled*.js', 'src/components/collective-page/*.js'],
},
{
name: 'Collective Page',
components: 'src/components/collective-page/*.js',
description: 'These components are used on the donate/contribute flow.',
},
{
name: 'Contribution Flow',
components: 'src/components/Contribute*.js',
description: 'These components are used on the donate/contribute flow.',
},
{
name: 'Grid',
content: 'styleguide/pages/Grid.md',
sections: [
{
name: 'Box',
content: 'styleguide/examples/Box.md',
},
{
name: 'Flex',
content: 'styleguide/examples/Flex.md',
},
],
},
],
skipComponentsWithoutExample: true,
styleguideComponents: {
Wrapper: path.join(__dirname, 'styleguide/Wrapper'),
},
styles: {
Blockquote: {
blockquote: {
borderLeft: '3px solid grey',
margin: '16px 0',
padding: '0 32px',
},
},
},
title: 'Open Collective Frontend Style Guide',
usageMode: 'expand',
webpackConfig: {
resolve: { extensions: ['.js', '.json'] },
stats: { children: false, chunks: false, modules: false, reasons: false },
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [{ loader: 'babel-loader', options: { cacheDirectory: true } }],
},
{
test: /components\/.*\.(svg)$/,
use: {
loader: 'url-loader',
options: {
limit: 1000000,
},
},
},
],
},
},
}; |
I can confirm this, but it does not seem to be related to v9.0.4 or v9.0.5. I had the same issue without updating any dependencies in my project. I simply did After some digging, it seems to be related to:
I got rid of it by upgrading all my |
It looks like upgrading ESLint fixed it 😃 |
Unfortunately upgrading eslint didn't fix it for me. But it seemed to be related to the version of
I suspect I had some dependency that was using the old version of acorn that was causing the problem. |
Seeing this in a nascent project, currently very basic deps/config. I've tried reinstalling and updating {
"name": "fepdx-react-component-library",
"version": "0.1.0",
"description": "React components to encapsulate the design for FEPDX projects.",
"main": "index.js",
"scripts": {
"start": "styleguidist server",
"build": "rimraf dist && babel src --out-dir dist",
"test": "jest"
},
"author": "Christoph Saxe",
"license": "ISC",
"dependencies": {
"@emotion/core": "^10.0.10",
"emotion-theming": "^10.0.10",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-styleguidist": "^9.1.2",
"webpack": "^4.32.2"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@babel/preset-react": "^7.0.0",
"@emotion/babel-preset-css-prop": "^10.0.9",
"babel-jest": "^24.8.0",
"babel-loader": "^8.0.6",
"jest": "^24.8.0",
"react-test-renderer": "^16.8.6",
"rimraf": "^2.6.3"
}
} styleguide.config.js: module.exports = {
webpackConfig: {
module: {
rules: [
{
test: /\.js?$/,
exclude: /node_modules/,
loader: 'babel-loader',
}
]
}
},
components: 'src/components/**/[A-Z]*.js',
}; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I have the same problem. 9.0.4 works but 9.0.5 have the error. |
It works for me! |
Changing from npm to yarn solved this problem in my project. Seems like something's wrong in the dependency tree? #1321 (comment) and other comments on this issue indicate this. |
Yeah, my colleague is anti shorthand so we don't have this properly configured (maybe I'll convince him to switch with this!). So, I fixed it by doing the downgrade with: |
This comment has been minimized.
This comment has been minimized.
I was experiencing the same "unexpected token" issue in all of my .md React component examples in one of my libraries when using the latest version of To expand on @cisen's fix posted above, I determined that the issue was with the latest version of Specific steps: # remove dependencies and delete lock file
rm -rf node_modules && rm -rf package-lock.json
# install + add acorn to devDependencies
npm install --save-dev acorn@^6.3.0
# re-install everything from package.json
npm install Additional context:
|
@dustin-ruetz's solution worked for me! rm -rf node_modules && rm -rf package-lock.json # nix dependencies + lockfile
npm install --save-dev acorn@^6.3.0 # save acorn as dev dependency
npm install # reinstall e'erything else |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Seems that explicitly installing npm cache clean --force
rm -rf node_modules package-lock.js
npm install --save-dev acorn@6
npm install |
I guess some of your project dependencies depends on Acorn 7, because Styleguidist depends only on 6.x. And all the solutions above is how to trick npm/yarn to use Acorn 6 with Stylegudist. And help with actually fixing the issue is very much appreciated. |
Buble doesn't support Acorn 7: And looks like something weird is happening when Acorn 7 is in the dependency tree. Buble tries to use Acorn 6 from its own I've made a simple failing test: package.json: {
"name": "acorn-test",
"private": true,
"dependencies": {
"acorn": "7.1.0",
"acorn-jsx": "5.1.0",
"buble": "0.19.8"
}
} test.js: var buble = require('buble');
var result = buble.transform(`<Button />`); And when I run
Looks at the stack trace I see that Buble uses Acorn 6.3.0 from it's own dependencies but it fails anyway. But looks like acorn-jsx will use whatever the latest version of Acorn is available in the tree. |
Also Buble seems to be in maintenance mode now, so we should consider migrating to something else: |
I've been trying to narrow the problem down a bit more: The test you posted still fails when {
"name": "acorn-test",
"private": true,
"dependencies": {
"acorn": "^7.1.0",
"buble": "0.19.8"
}
}
"peerDependencies": {
"acorn": "^6.0.0 || ^7.0.0"
}, So when In short this is definitely something that should be fixed upstream. |
EDIT: Never mind. This causes all examples to go to A possible fix here would be to lock Changing {
"name": "acorn-test",
"private": true,
"dependencies": {
"acorn": "^7.1.0",
"buble": "=0.19.4"
}
} works just fine. |
@sapegin Sorry for offtopic considering scope of this issue but what is the reason for using something like |
@malyzeli Primarily its size: babel-standalone is gigantic and we'll need to find a way to lazy load it somehow which is tricky because we need it to render all the examples. |
We also have same issue. https://react-google-maps-api-docs.netlify.com/ Nothing helps. |
@JustFly1984 This kind of comments don't add anything to the discussion and significantly contribute to maintainers burnout. Now I have to either lock this thread to prevent future spam comment, which will also prevent folks who are actually trying to help from posting useful comments. Or unsubscribe myself to stop receiving spam comments — my own mental health is definitely more important to me than someone's problem with their project. |
@sapegin sorry mate, I didn't mean to be rude. I use your open source project in my open source project. I'm building my project with tsdx, and it has acorn@7 in dependencies, so I can't add [email protected] to resolution in package.json, cos it breaks build. |
Looks like acornjs/acorn#887 fixed this! Since the release of |
@iansan5653 I've made that fix in #1495. |
Fix worked for us. Thanks! |
Tried it. Still have the issue |
@iamchathu check if you have semicolons everywhere. I had issues with files until I’ve set semicolons in place. This is not obvious, and it could be helpful if there was no semicolons required. |
@JustFly1984 I'm using to prettier rules to set semi colons and I double checked but seems there is an issue yet. |
I had to install react-styleguidist with yarn (vs npm) to have PROPS & METHODSi working.
Now it works but i have Syntax errors for all my components (with defaultExample set to true and components with their own examples too):
Current behavior
in the .md file
results in
and
results in
here is an example of a simple component code :
Expected behavior
The code example should display my component
The text was updated successfully, but these errors were encountered: