Skip to content
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

Warning: Couldn't find preset "env" relative to directory #91

Open
essteffan opened this issue May 8, 2018 · 11 comments
Open

Warning: Couldn't find preset "env" relative to directory #91

essteffan opened this issue May 8, 2018 · 11 comments

Comments

@essteffan
Copy link

Hi Guys
I need to use babel in one project and I've installed and i get this error when running grunt (edited)
Warning: Couldn't find preset "env" relative to directory "/Users/essteffan/Sites/div//live..ro/web" Use --force to continue.

I'm using Grunt

and i have a concat before babel and after i have an uglify

My babel config is:

babel: {
options: {
sourceMap: true,
presets: ['@babel/preset-env']
},
dist: {
files: {
'../js/app.min.js': '../js/app.js'
}
}
},

If i comment this line i have no errors: '../js/app.min.js': '../js/app.js'
Somehow i thing around there is the problem.

Could you please advice how to make it work?

@xtuc
Copy link
Member

xtuc commented May 8, 2018

Could you please share your package.json? have you installed @babel/preset-env?

@essteffan
Copy link
Author

Sure, Thanks for quick response

{
"name": "Grunt",
"verion": "0.0.1",
"Description": "Grunt",
"devDependencies": {
"@babel/core": "^7.0.0-beta.46",
"@babel/preset-env": "^7.0.0-beta.46",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.6.1",
"grunt": "~1.0.1",
"grunt-babel": "^7.0.0",
"grunt-contrib-compass": "~1.1.1",
"grunt-contrib-concat": "~1.0.1",
"grunt-contrib-jshint": "~1.1.0",
"grunt-contrib-uglify": "~3.3.0",
"grunt-contrib-watch": "~1.0.0",
"grunt-text-replace": "~0.4.0",
"load-grunt-tasks": "^4.0.0"
}
}

@xtuc
Copy link
Member

xtuc commented May 8, 2018

Thanks, have you tried with earlier betas? I think your issue is due to the new config resolution. I would recommend you using babel.config.js at the root of your project.

The configuration there will be applied everywhere in your project. .babelrc is now only applied when it is in the current directory.

@essteffan
Copy link
Author

I've added that in root, but how do i link Gruntfile.js to this file?
Sorry i'm a php developer, haven't used babel

@xtuc
Copy link
Member

xtuc commented May 9, 2018

Could you please share your gruntfile?

@noobiek
Copy link

noobiek commented May 9, 2018

Hi,
Same thing here.

Couldn't find preset "@babel/env" relative to directory "/projects/geness-web-plugins/corp/grunt"

I don't think this is anyhow connected to contat/uglify.
Gruntfile contains this simple task.
babel: { options: { sourceMap: false, presets: ['@babel/preset-env'] }, dist: { files: { 'plugin.js': 'plugin.js' } } }
And I've tried installing whatever is suggested everywhere
{ "name": "UnderScoreTemplate", "version": "0.1.0", "devDependencies": { "@babel/preset-env": "^7.0.0-beta.46", "babel-core": "^6.26.3", "babel-loader": "^7.1.4", "eslint": "^4.17.0", "grunt": "^0.4.5", "grunt-babel": "^7.0.0", "grunt-contrib-concat": "^1.0.1", "grunt-contrib-cssmin": "^2.2.0", "grunt-contrib-jst": "^1.0.0", "grunt-contrib-uglify": "^3.3.0", "grunt-string-replace": "^1.3.1", "load-grunt-tasks": "^4.0.0" }, "dependencies": { "babel-preset-env": "^1.6.1" } }
And I've placed .babelrc and babel.config.js to same dir.
No luck.

@noobiek
Copy link

noobiek commented May 9, 2018

I started afresh.

babel.config.js from your post earlier.

Gruntfile.js file:
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
babel: {
options: {
sourceMap: true,
presets: ['@babel/preset-env']
},
dist: {
files: {
'app.js': 'app.js'
}
}
}
});
grunt.registerTask('default', ['babel']);
}

.babelrc file;
{
"presets": [
["@babel/env", {
"targets": {
"browsers": ["last 2 versions", "safari >= 7"]
},
"useBuiltIns": "usage",
"debug": true
}]
]
}

package.json file:
{
"name": "grunt2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.0.0-beta.46",
"@babel/preset-env": "^7.0.0-beta.46",
"babel-core": "^6.26.3",
"grunt": "^1.0.2",
"grunt-babel": "^7.0.0",
"load-grunt-tasks": "^4.0.0"
}
}

Without babel-core I get
Loading "babel.js" tasks...ERROR
>> Error: Cannot find module 'babel-core'
Warning: Task "babel" not found. Use --force to continue.

With babel-core same result:
Warning: Couldn't find preset "@babel/env" relative to directory "/test/grunt" Use --force to continue.

Node is v9.11.1, btw.

@noobiek
Copy link

noobiek commented May 9, 2018

Switched to this "env" instead https://babeljs.io/docs/plugins/preset-env
It works.

@davegreenwp
Copy link

davegreenwp commented Jul 27, 2018

Having a similar situation in one of our workflow repos.

In my Babel task...

options: {
	presets: [
		'@babel/preset-env'
	]
},

In my package.json

"@babel/core": "^7.0.0-beta.54",
"@babel/preset-env": "^7.0.0-beta.54",
"grunt-babel": "8.0.0-beta.0",

Error on grunt...

Warning: Cannot find module '@babel/preset-env' from <path>

Tried to replace the @babel/preset-env module with babel-preset-env, switching the preset to env in the Babel task as suggested above. Also tried dropping babel.config.js into the folder in question.

No joy. 🤔

@noobiek
Copy link

noobiek commented Jul 27, 2018

Hi @davetgreen

Since I made this work then you can too :)
Post your changed minimal configs here, please. Let's take a look.

My Gruntfile.js has babel task configed this way:

    babel: {
      options: {
        sourceMap: false,
        presets: ['env']
      },
      dist: {
        files: {
          'jsbundle.babel.js': 'jsbundle.js'
        }
      }
    }

And .babelrc in same folder:

{
  "presets": [
    ["env", {
      "targets": {
        "browsers": ["last 2 versions", "safari >= 7"]
      }
    }]
  ]
}

@Belsi
Copy link

Belsi commented Feb 12, 2019

I have the same problem and was fixed by add .babelrc file.

// babel.config.js
module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          node: 'current',
        },
      },
    ],
  ],
  plugins: ['transform-flow-strip-types'],
};

and after add file:

// .babelrc
{
  "presets": ["env", "flow", "stage-1"]
}

It start work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants