Gulp Babel({ presets: ["env"] }), does not see external directory

Asked

Viewed 56 times

0

I am using Gulp to compile my JS files. I have TWO folders where there are JS files, one INSIDE the project (daughter folder themes/) and another this FORA (parent folder modules/).

When using the:

babel({
  minified: true,
  presets: ["env"]
}))

js files from within the project (folder themes/) compile normally, but those who are OUT give error in presets: ["env"].

Error: Couldn't find preset "env" relative to directory "C:\\projetos\\...

It seems that the presets: ["env"] cannot see the parent folders, in this case what is above the folder themes/.

Obs 1: The archive gulpfile.js that rotates the presets: ["env"] this inside the folder themes/.

Obs 2: Any other Gulp function, such as copying files from the folder modules/ into the folder themes/ works normally, it’s just the presets: ["env"] that gives the error.

Folder structure:

projetos/
  |-modules/
    |-js/file-module.js
  |-profile/
    |-contrib/
      |-themes/
        |-js/file-theme.js
      node_modules/
      gulpfile.js

Short question:

How do I make for the preset: ["env"] that runs from within the file gulpfile.js view the file modules/js/file-module.js recalling that the gulpfile.js this inside the folder themes/?

1 answer

0

I managed to solve by adding in presets the name of the folder where it would fetch the package and then putting the . map(require.resolve) to find the folder.

The final code went like this:

.pipe(babel({
  presets: ['babel-preset-env'].map(require.resolve)
}))

// Também é possível adicionando o preset abaixo:

.pipe(babel({ 
  presets: ['@babel/preset-env'] 
}))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.