-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Running gatsby through npm script from another directory throws an error #235
Comments
If you could create a test repo here on Github that reproduces this error, that'd be really helpful. |
This looks like a .babelrc thing. I'm guessing that the docs folder does not have a .babelrc in it. Babel will crawl a directory structure upward until it finds .babelrc and use the configuration and the dependencies required relative to that directory. So, in your case it looks like babel crawled up to your root directory Copy or move the .babelrc into docs should fix your problem
|
For some reasons, the error has changed on the plugin Having a babelrc file inside my docs directory doesn't solve the issue though. But I think you're right, gatsby/babel is searching for plugins in the root, instead of the |
Now I'm just guessing without seeing a repo, but make sure that the |
Oh.. good to know the site also needs the babel plugin even if it doesn't directly use it. I'll test and will let you know |
Ok, I found the issue... It's because the docs website requires code from the root. Therefore, it seems that Babel is looking for plugins from the required file, not the source where it's run... https://github.com/tleunen/gatsby-issue-235 |
// What babel-loader wants to transpile
{ inputSourceMap: undefined,
sourceRoot: '/Users/ben/Code/gatsby-issue-235/docs',
filename: '/Users/ben/Code/gatsby-issue-235/src/index.js',
presets: [ 'react-hmre', 'react', 'es2015', 'stage-1' ],
plugins: [ 'add-module-exports' ],
sourceMap: false,
sourceFileName: '../src/index.js' } https://github.com/babel/babel/blob/4c371132ae7321f6d08567eab54a59049e07f246/packages/babel-core/src/transformation/file/options/option-manager.js#L422 Not sure if it's broken, or intended to be such that you cannot require files outside of your project's directory. It's always cool to find out why something isn't working though. |
I'm not sure if this helps at all, but I ran into this when |
This change makes it so the user doesn't need to specify their plugins. If they want to override it they would need to modify the js loader config using the modifyWebpackConfig API. Ideally we would support a user provided .babelrc as well. ``` exports.modifyWebpackConfig = function(config, env) { config.removeLader('js') config.loader('js', { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel', query: { presets: [ 'babel-preset-react', 'babel-preset-es2015', 'babel-preset-stage-0', ].map(require.resolve), plugins: [ 'babel-plugin-add-module-exports', 'babel-plugin-transform-decorators-legacy', ].map(require.resolve), }, }) return config; } ``` Fixes gatsbyjs#235. Requires less user package.json dependencies unless the user wants to add babel plugins (Users no longer need to provide babel-plugins of any kind in their project as gatsby provides them)
Fixed in #279 and released in 0.11 |
I have a npm script with this command
cd docs && ./node_modules/.bin/gatsby develop
.So gatsby and all the dependencies to run a gatsby website are inside the directory
docs
, and this error is thrown:If, instead, gatsby is also installed in the root directory and I switch the command for
cd docs && gatsby develop
, everything works. Having gatsby only in the root doesn't work.The text was updated successfully, but these errors were encountered: