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

Error: Options {"loose":true} when compiling from within npm package #6974

Open
aamorozov opened this Issue Dec 4, 2017 · 9 comments

Comments

Projects
None yet
6 participants
@aamorozov

aamorozov commented Dec 4, 2017

Choose one: is this a bug report or feature request?

Bug(unless i'm doing it wrong).

Input Code

exportFunc.js

export default function main() {
console.log('Function that is being exported')
}

main.js

require('babel-register')();
const main = require('./exportFunc.js')

Babel/Babylon Configuration (.babelrc, package.json, cli command)

{
  "plugins": [
    "add-module-exports",
    "transform-object-rest-spread",
    [
      "transform-runtime",
      {
        "regenerator": true
      }
    ]
  ],
  "presets": [["env", {"targets": {"node": "current"}}]]
}

Expected Behavior

It should compile the module.

Current Behavior

Upon installing the package within the post-install script it throws an error:

./node_modules/babel-core/lib/transformation/file/options/option-manager.js:328
        throw e;
        ^

Error: Options {"loose":true} passed to ./node_modules/babel-preset-env/lib/index.js which does 
not accept options. (While processing preset: "./node_modules/babel-preset-env/lib/index.js") 
(While processing preset: "./node_modules/babel-preset-env/lib/index.js")

Possible Solution

Context

I've tried all suggestions in this repo/stack related to Error: Options {"loose":true} but can't make it work.

Your Environment

software version(s)
Babel "babel-register": "^6.26.0", "babel-preset-env": "^1.6.1",
Babylon Not using directly
node v8.9.1
npm 5.5.1
Operating System MacOS Sierra v. 10.12.6
@babel-bot

This comment has been minimized.

Show comment
Hide comment
@babel-bot

babel-bot Dec 4, 2017

Collaborator

Hey @aamorozov! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

Collaborator

babel-bot commented Dec 4, 2017

Hey @aamorozov! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo

This comment has been minimized.

Show comment
Hide comment
@nicolo-ribaudo

nicolo-ribaudo Dec 4, 2017

Member

Can you provide your package.json and the post-install script?

Member

nicolo-ribaudo commented Dec 4, 2017

Can you provide your package.json and the post-install script?

@aamorozov

This comment has been minimized.

Show comment
Hide comment
@aamorozov

aamorozov Dec 4, 2017

@nicolo-ribaudo Script itself is internal to the org, so can only provide how i call it and babel related packages, but inside the script is the exact same structure i noted in the code example in the issue - requiring functions that are being exported with export default and on top of the file is require('babel-register')():

  "scripts": {
    "postinstall": "node setupConfig.js"
  },

babel packages

    "babel-plugin-add-module-exports": "^0.2.1",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.6.1",
    "babel-register": "^6.26.0",
    "babel-cli": "^6.26.0",
    "babel-core": "^6.3.21",
    "babel-eslint": "^8.0.3",
    "babel-polyfill": "^6.3.14",
    "babel-runtime": "^6.26.0",

aamorozov commented Dec 4, 2017

@nicolo-ribaudo Script itself is internal to the org, so can only provide how i call it and babel related packages, but inside the script is the exact same structure i noted in the code example in the issue - requiring functions that are being exported with export default and on top of the file is require('babel-register')():

  "scripts": {
    "postinstall": "node setupConfig.js"
  },

babel packages

    "babel-plugin-add-module-exports": "^0.2.1",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.6.1",
    "babel-register": "^6.26.0",
    "babel-cli": "^6.26.0",
    "babel-core": "^6.3.21",
    "babel-eslint": "^8.0.3",
    "babel-polyfill": "^6.3.14",
    "babel-runtime": "^6.26.0",
@nicolo-ribaudo

This comment has been minimized.

Show comment
Hide comment
@nicolo-ribaudo

nicolo-ribaudo Dec 5, 2017

Member

Can you try to update babel-core to 6.26.x? Preset options where added in version 6.13.0.

Member

nicolo-ribaudo commented Dec 5, 2017

Can you try to update babel-core to 6.26.x? Preset options where added in version 6.13.0.

@aamorozov

This comment has been minimized.

Show comment
Hide comment
@aamorozov

aamorozov Dec 5, 2017

@nicolo-ribaudo
Just tried, getting the same error. {"loose": true} is not being set from anywhere in my code, double checked that.

Update: should've mentioned that in the issue, everything works when running node script in the lib itself, it fails only when compiling the npm package upon adding it to the project.

aamorozov commented Dec 5, 2017

@nicolo-ribaudo
Just tried, getting the same error. {"loose": true} is not being set from anywhere in my code, double checked that.

Update: should've mentioned that in the issue, everything works when running node script in the lib itself, it fails only when compiling the npm package upon adding it to the project.

@loganfsmyth

This comment has been minimized.

Show comment
Hide comment
@loganfsmyth

loganfsmyth Dec 5, 2017

Member

I don't think we have enough to answer as-is, but to me this sounds like an issue with babel-register being used in a place where it is actually trying to run babel-preset-env on itself, which usually happens if people do ignore: false, but you don't appear to be doing that. e.g. Babel's own require("babel-preset-env") triggers babel-register, which then tries to use env to compile itself. Now sure why it'd be happening with what you've shown so far.

Member

loganfsmyth commented Dec 5, 2017

I don't think we have enough to answer as-is, but to me this sounds like an issue with babel-register being used in a place where it is actually trying to run babel-preset-env on itself, which usually happens if people do ignore: false, but you don't appear to be doing that. e.g. Babel's own require("babel-preset-env") triggers babel-register, which then tries to use env to compile itself. Now sure why it'd be happening with what you've shown so far.

@jojohappy

This comment has been minimized.

Show comment
Hide comment
@jojohappy

jojohappy Jan 25, 2018

I also meet this problem, the babel-register configuration is

{
  only: [ './views', './src' ],
  presets: [ 'react', [ 'env', [Object] ] ]
}

In babel-core, the regular expression of only will be generated by babel-core/util/regexify as following below

{ only: [ /(?:(?=.)views)/i, /(?:(?=.)src)/i ] }

I run the app in /usr/src/app, the /usr/src/app/node_modules/babel-preset-env/lib/index.js will be matched and compile itself.

Is it a bug to generate the regular expression?

jojohappy commented Jan 25, 2018

I also meet this problem, the babel-register configuration is

{
  only: [ './views', './src' ],
  presets: [ 'react', [ 'env', [Object] ] ]
}

In babel-core, the regular expression of only will be generated by babel-core/util/regexify as following below

{ only: [ /(?:(?=.)views)/i, /(?:(?=.)src)/i ] }

I run the app in /usr/src/app, the /usr/src/app/node_modules/babel-preset-env/lib/index.js will be matched and compile itself.

Is it a bug to generate the regular expression?

@npahucki

This comment has been minimized.

Show comment
Hide comment
@npahucki

npahucki Jun 21, 2018

I'm running into this as well when using react-static. It works fine if you run in the root directory, but running in the npm postintstall fails with

Error: Options {"loose":true} passed to /xxx/test/node_modules/babel-preset-env/lib/index.js which does not accept options. (While processing preset: "/xxx/test/node_modules/babel-preset-env/lib/index.js") (While processing preset: "/xxx/test/node_modules/babel-preset-env/lib/index.js") (While processing preset: "/xxx/test/node_modules/react-static/babel-preset.js")
    at /xxx/test/node_modules/babel-core/lib/transformation/file/options/option-manager.js:314:17

babel-core is 6.26.0

Has there been any progress on this?
@aamorozov did you ever find a solution?

npahucki commented Jun 21, 2018

I'm running into this as well when using react-static. It works fine if you run in the root directory, but running in the npm postintstall fails with

Error: Options {"loose":true} passed to /xxx/test/node_modules/babel-preset-env/lib/index.js which does not accept options. (While processing preset: "/xxx/test/node_modules/babel-preset-env/lib/index.js") (While processing preset: "/xxx/test/node_modules/babel-preset-env/lib/index.js") (While processing preset: "/xxx/test/node_modules/react-static/babel-preset.js")
    at /xxx/test/node_modules/babel-core/lib/transformation/file/options/option-manager.js:314:17

babel-core is 6.26.0

Has there been any progress on this?
@aamorozov did you ever find a solution?

@loganfsmyth

This comment has been minimized.

Show comment
Hide comment
@loganfsmyth

loganfsmyth Jun 22, 2018

Member

@npahucki As mentioned earlier, generally it is an issue with babel-register or babel-node's configuration. If you include that we can try to direct you, but the error on its own is not enough information.

Member

loganfsmyth commented Jun 22, 2018

@npahucki As mentioned earlier, generally it is an issue with babel-register or babel-node's configuration. If you include that we can try to direct you, but the error on its own is not enough information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment