better-docs icon indicating copy to clipboard operation
better-docs copied to clipboard

Error: [BABEL] unknown: Preset /* your preset */ requires a filename to be set when babel is called directly,

Open Ridermansb opened this issue 5 years ago • 2 comments

Trying to generate docs with typescript but I received an error..

Error: [BABEL] unknown: Preset /* your preset */ requires a filename to be set when babel is called directly,

This is my babel.config.json

{
    "presets": [
        [
            "@babel/preset-typescript",
            {
                "jsxPragma": "j"
            }
        ],
        [
            "@babel/preset-env",
            {
                "modules": false,
                "loose": true,
                "useBuiltIns": "entry",
                "corejs": 3
            }
        ]
    ],
    "plugins": [
        "syntax-async-functions",
        "@babel/plugin-transform-async-to-generator",
        [
            "@babel/plugin-transform-arrow-functions",
            {
                "spec": true,
                "loose": true
            }
        ],
        [
            "@babel/plugin-transform-runtime",
            {
                "absoluteRuntime": false,
                "corejs": 3,
                "helpers": true,
                "regenerator": true,
                "useESModules": false,
                "version": "7.0.0-beta.0"
            }
        ],
        [
            "module-resolver",
            {
                "root": [
                    "."
                ],
                "extensions": [
                    ".js",
                    ".jsx",
                    ".ts"
                ],
                "alias": {
                    "^@components/(.+)": "./src/components/\\1",
                    "^@assets/(.+)": "./src/assets/\\1",
                    "^@pages/(.+)": "./src/pages/\\1",
                    "^@store$": "./src/store/index.js",
                    "^@store/(.+)": "./src/store/\\1",
                    "^@api$": "./src/api/index.js",
                    "^@api/(.+)": "./src/api/\\1",
                    "^@base$": "./src/base.js",
                    "^@validator$": "./src/validator/index.js",
                    "^@validator/(.+)": "./src/validator/\\1",
                    "^@utils$": "./src/utils.js"
                }
            }
        ],
        [
            "@babel/plugin-transform-react-jsx",
            {
                "pragma": "h",
                "pragmaFrag": "Fragment"
            }
        ],
        [
            "@babel/plugin-proposal-object-rest-spread",
            {
                "loose": true,
                "useBuiltIns": true
            }
        ],
        [
            "@babel/plugin-transform-destructuring",
            {
                "loose": true,
                "useBuiltIns": true
            }
        ],
        "@babel/plugin-syntax-dynamic-import",
        [
            "@babel/plugin-proposal-class-properties",
            {
                "spec": true
            }
        ],
        "transform-react-remove-prop-types"
    ],
    "env": {
        "development": {
            "plugins": [
                "react-hot-loader/babel",
                "@babel/plugin-transform-react-jsx-source",
                "@babel/plugin-transform-react-display-name"
            ]
        }
    }
}

With this error


    Error: [BABEL] unknown: Preset /* your preset */ requires a filename to be set when babel is called directly,
    `
    babel.transform(code, { filename: 'file.ts', presets: [/* your preset */] });
`
See https://babeljs.io/docs/en/options#filename for more information.
at validateIfOptionNeedsFilename (./web/node_modules/@babel/core/lib/config/full.js:275:11)
at options.overrides.forEach.overrideOptions (./web/node_modules/@babel/core/lib/config/full.js:287:52)
at Array.forEach (<anonymous>)
at validatePreset (./web/node_modules/@babel/core/lib/config/full.js:287:25)
at loadPresetDescriptor (./web/node_modules/@babel/core/lib/config/full.js:294:3)
at loadPresetDescriptor.next (<anonymous>)
at recurseDescriptors (./web/node_modules/@babel/core/lib/config/full.js:108:30)
at recurseDescriptors.next (<anonymous>)
at loadFullConfig (./web/node_modules/@babel/core/lib/config/full.js:143:6)
at loadFullConfig.next (<anonymous>)
at Object.parse (./web/node_modules/@babel/core/lib/parse.js:28:45)
at parse.next (<anonymous>)
at evaluateSync (./web/node_modules/gensync/index.js:245:28)
at Object.sync (./web/node_modules/gensync/index.js:85:14)
at Object.parse (./web/node_modules/react-docgen/dist/babelParser.js:66:20)
at Object.parse (./web/node_modules/recast/lib/parser.js:32:30)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! web@ generate-docs: `jsdoc -c jsdoc.json`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the web@ generate-docs script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Ridermansb avatar Apr 25 '20 16:04 Ridermansb

Same problem here `DEBUG: Environment info: {"env":{"conf":{"plugins":["plugins/markdown","node_modules/better-docs/component"],"recurseDepth":10,"source":{"includePattern":".+\.js(doc|x)?$","excludePattern":"(^|\/|\\)","include":["src"]},"sourceType":"module","tags":{"allowUnknownTags":true,"dictionaries":["jsdoc","closure"]},"templates":{"monospaceLinks":false,"cleverLinks":false,"better-docs":{"name":"My React components"}},"opts":{"destination":"docs","recurse":true,"readme":"README.md"}},"opts":{"":[],"configure":"jsdoc.conf.json","debug":true,"destination":"docs","recurse":true,"readme":"README.md","encoding":"utf8"}}} DEBUG: Parsing source files: ["/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/boxContainer.js","/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/hello.js","/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/index.js","/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/touchable.js","/Users/abraaobarros/Projetos/react_native/Base/src/index.js"] Parsing /Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/boxContainer.js ... Parsing /Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/hello.js ... /Users/abraaobarros/Projetos/react_native/Base/node_modules/better-docs/component.js:67 throw error ^

Error: [BABEL] unknown: Preset /* your preset */ requires a filename to be set when babel is called directly,

babel.transform(code, { filename: 'file.ts', presets: [/* your preset */] });

See https://babeljs.io/docs/en/options#filename for more information. at validateIfOptionNeedsFilename (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:275:11) at options.overrides.forEach.overrideOptions (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:287:52) at Array.forEach () at validatePreset (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:287:25) at loadPresetDescriptor (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:294:3) at loadPresetDescriptor.next () at recurseDescriptors (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:108:30) at recurseDescriptors.next () at loadFullConfig (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:143:6) at loadFullConfig.next () Base $yarn docs --debug yarn run v1.22.4 $ jsdoc -c jsdoc.conf.json --debug DEBUG: JSDoc 3.6.4 (Mon, 06 Apr 2020 19:30:09 GMT) DEBUG: Environment info: {"env":{"conf":{"plugins":["plugins/markdown","node_modules/better-docs/component"],"recurseDepth":10,"source":{"includePattern":".+\.js(doc|x)?$","excludePattern":"(^|\/|\\)","include":["src"]},"sourceType":"module","tags":{"allowUnknownTags":true,"dictionaries":["jsdoc","closure"]},"templates":{"monospaceLinks":false,"cleverLinks":false,"better-docs":{"name":"My React components"}},"opts":{"destination":"docs","recurse":true,"readme":"README.md"}},"opts":{"":[],"configure":"jsdoc.conf.json","debug":true,"destination":"docs","recurse":true,"readme":"README.md","encoding":"utf8"}}} DEBUG: Parsing source files: ["/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/boxContainer.js","/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/hello.js","/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/index.js","/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/touchable.js","/Users/abraaobarros/Projetos/react_native/Base/src/index.js"] Parsing /Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/boxContainer.js ... Parsing /Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/hello.js ... /Users/abraaobarros/Projetos/react_native/Base/node_modules/better-docs/component.js:67 throw error ^

Error: [BABEL] unknown: Preset /* your preset */ requires a filename to be set when babel is called directly,

babel.transform(code, { filename: 'file.ts', presets: [/* your preset */] });

See https://babeljs.io/docs/en/options#filename for more information. at validateIfOptionNeedsFilename (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:275:11) at options.overrides.forEach.overrideOptions (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:287:52) at Array.forEach () at validatePreset (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:287:25) at loadPresetDescriptor (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:294:3) at loadPresetDescriptor.next () at recurseDescriptors (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:108:30) at recurseDescriptors.next () at loadFullConfig (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:143:6) at loadFullConfig.next () Base $yarn docs --debug yarn run v1.22.4 $ jsdoc -c jsdoc.conf.json --debug DEBUG: JSDoc 3.6.4 (Mon, 06 Apr 2020 19:30:09 GMT) DEBUG: Environment info: {"env":{"conf":{"plugins":["plugins/markdown","node_modules/better-docs/component"],"recurseDepth":10,"source":{"includePattern":".+\.js(doc|x)?$","excludePattern":"(^|\/|\\)","include":["src"]},"sourceType":"module","tags":{"allowUnknownTags":true,"dictionaries":["jsdoc","closure"]},"templates":{"monospaceLinks":false,"cleverLinks":false,"better-docs":{"name":"My React components"}},"opts":{"destination":"docs","recurse":true,"template":"node_modules/better-docs","readme":"README.md"}},"opts":{"":[],"configure":"jsdoc.conf.json","debug":true,"destination":"docs","recurse":true,"template":"node_modules/better-docs","readme":"README.md","encoding":"utf8"}}} DEBUG: Parsing source files: ["/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/boxContainer.js","/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/hello.js","/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/index.js","/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/touchable.js","/Users/abraaobarros/Projetos/react_native/Base/src/index.js"] Parsing /Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/boxContainer.js ... Parsing /Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/hello.js ... /Users/abraaobarros/Projetos/react_native/Base/node_modules/better-docs/component.js:67 throw error ^

Error: [BABEL] unknown: Preset /* your preset */ requires a filename to be set when babel is called directly,

babel.transform(code, { filename: 'file.ts', presets: [/* your preset */] });

See https://babeljs.io/docs/en/options#filename for more information. at validateIfOptionNeedsFilename (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:275:11) at options.overrides.forEach.overrideOptions (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:287:52) at Array.forEach () at validatePreset (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:287:25) at loadPresetDescriptor (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:294:3) at loadPresetDescriptor.next () at recurseDescriptors (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:108:30) at recurseDescriptors.next () at loadFullConfig (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:143:6) at loadFullConfig.next () Base $yarn docs --debug yarn run v1.22.4 $ jsdoc -c jsdoc.conf.json --debug DEBUG: JSDoc 3.6.4 (Mon, 06 Apr 2020 19:30:09 GMT) DEBUG: Environment info: {"env":{"conf":{"plugins":["plugins/markdown","node_modules/better-docs/component"],"recurseDepth":10,"source":{"includePattern":".+\.js(doc|x)?$","excludePattern":"(^|\/|\\)","include":["src"]},"sourceType":"module","tags":{"allowUnknownTags":true,"dictionaries":["jsdoc","closure"]},"templates":{"monospaceLinks":false,"cleverLinks":false,"better-docs":{"name":"My React components"}},"opts":{"destination":"docs","recurse":true,"template":"node_modules/better-docs","readme":"README.md"}},"opts":{"":[],"configure":"jsdoc.conf.json","debug":true,"destination":"docs","recurse":true,"template":"node_modules/better-docs","readme":"README.md","encoding":"utf8"}}} DEBUG: Parsing source files: ["/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/boxContainer.js","/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/hello.js","/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/index.js","/Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/touchable.js","/Users/abraaobarros/Projetos/react_native/Base/src/index.js"] Parsing /Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/boxContainer.js ... Parsing /Users/abraaobarros/Projetos/react_native/Base/src/components/atoms/hello.js ... /Users/abraaobarros/Projetos/react_native/Base/node_modules/better-docs/component.js:67 throw error ^

Error: [BABEL] unknown: Preset /* your preset */ requires a filename to be set when babel is called directly,

babel.transform(code, { filename: 'file.ts', presets: [/* your preset */] });

See https://babeljs.io/docs/en/options#filename for more information. at validateIfOptionNeedsFilename (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:275:11) at options.overrides.forEach.overrideOptions (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:287:52) at Array.forEach () at validatePreset (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:287:25) at loadPresetDescriptor (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:294:3) at loadPresetDescriptor.next () at recurseDescriptors (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:108:30) at recurseDescriptors.next () at loadFullConfig (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/config/full.js:143:6) at loadFullConfig.next () at Object.parse (/Users/abraaobarros/Projetos/react_native/Base/node_modules/@babel/core/lib/parse.js:28:45) at parse.next () at evaluateSync (/Users/abraaobarros/Projetos/react_native/Base/node_modules/gensync/index.js:245:28) at Object.sync (/Users/abraaobarros/Projetos/react_native/Base/node_modules/gensync/index.js:85:14) at Object.parse (/Users/abraaobarros/Projetos/react_native/Base/node_modules/react-docgen/dist/babelParser.js:66:20) at Object.parse (/Users/abraaobarros/Projetos/react_native/Base/node_modules/recast/lib/parser.js:32:30) error Command failed with exit code 1`

abrahampe avatar May 17 '20 20:05 abrahampe

@Ridermansb, @abrahampe I had the same issue. I successfully resolve it by changing line 50 of ./src/react-wrapper.jsx :

const src = Babel.transform(wrapper, { presets: ['react', 'es2015'] }).code

by :

const src = Babel.transform(wrapper, { presets: ["@babel/preset-react", "@babel/preset-env"] }).code

Let me know if it resolve the issue for you too. (don't forget to build better-docs)

xburelle avatar Jul 21 '20 10:07 xburelle