Skip to content

Commit

Permalink
fix: resolve the absolute path to the current directory (#266)
Browse files Browse the repository at this point in the history
When running `cli-app-scripts test` in an app, the line:

    extends: './app.babel.config'

Incorrectly resolves from the current working directory:

    Cannot find module './app.babel.config' from '/home/varl/dev/dhis2/apps/usage-analytics'

We can use `path.resolve` + `__dirname`[1] to resolve the absolute path
of the `app.babel.config.js` file relatively to `babel.config.js`.

[1] https://nodejs.org/api/globals.html#globals_dirname
  • Loading branch information
varl committed Jan 16, 2020
1 parent 1352058 commit 190c111
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cli/config/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const path = require('path')

const browserTargets = require('./.browserlistrc')
const jestTargets = { node: 'current' }

const isTest = process.env.NODE_ENV === 'test'
const targets = isTest ? jestTargets : browserTargets

const appBabelConfig = path.resolve(__dirname, 'app.babel.config')

module.exports = {
extends: './app.babel.config',
extends: appBabelConfig,
presets: [
require('@babel/preset-react'),
require('@babel/preset-typescript'),
Expand Down

0 comments on commit 190c111

Please sign in to comment.