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

Using babelify with new scoped packages #251

Closed
larsgw opened this issue Nov 12, 2017 · 7 comments · Fixed by #255
Closed

Using babelify with new scoped packages #251

larsgw opened this issue Nov 12, 2017 · 7 comments · Fixed by #255

Comments

@larsgw
Copy link
Contributor

larsgw commented Nov 12, 2017

Today I installed the new scoped packages of babel, e.g. @babel/core etc., including the plugins, e.g. @babel/plugin-proposal-pipeline-operator etc. However, babelify@8 still requires the 'old' babel-core package, AFAICT. I first installed babel-core@6 by accident, which had problems with the new .babelrc plugin syntax (before it would prefix babel-plugin- to get the package, I think; now it'd need to add plugin- between @babel/ and the plugin name).

However, babel-core@7.0.0-beta.3, the latest I could find, gave the following error instead:

/home/larsw/project_dir/node_modules/babelify/index.js:65
  if (!babel.util.canCompile(filename, extensions)) {
                  ^

TypeError: Cannot read property 'canCompile' of undefined
  at /home/larsw/project_dir/node_modules/babelify/index.js:65:21
  at Babelify (/home/larsw/project_dir/node_modules/babelify/index.js:10:36)
  at nr (/home/larsw/project_dir/node_modules/module-deps/index.js:301:23)
  at onfile (/home/larsw/project_dir/node_modules/resolve/lib/async.js:56:21)
  at onex (/home/larsw/project_dir/node_modules/resolve/lib/async.js:104:32)
  at /home/larsw/project_dir/node_modules/resolve/lib/async.js:24:24
  at FSReqWrap.oncomplete (fs.js:153:5)

Note: I'm not sure if it's possible to use babelify with the new scoped packages at all.

@larsgw
Copy link
Contributor Author

larsgw commented Nov 12, 2017

Here's my .babelrc:

{
  "presets": [
    ["@babel/env", {
      "targets": {
        "browser": [
          "> 1%",
          "last 10 versions",
          "ie > 7"
        ]
      }
    }]
  ],
  "plugins": [
    "@babel/proposal-unicode-property-regex"
  ],
  "env": {
    "test": {
      "plugins": ["istanbul"]
    }
  }
}

@noygal
Copy link

noygal commented Nov 13, 2017

Getting the same error after changing the `babel-core' to point to the new scoped packages:

  "dependencies": {
    "@babel/cli": "^7.0.0-beta.32",
    "@babel/core": "^7.0.0-beta.3",
    "@babel/preset-env": "^7.0.0-beta.32",
    "@babel/preset-react": "^7.0.0-beta.32",
    "@babel/preset-stage-0": "^7.0.0-beta.32",
    "babel-core": "@babel/cli",
    "babelify": "^8.0.0"
  }

@larsgw
Copy link
Contributor Author

larsgw commented Nov 13, 2017

I didn't even know you could do that. Does it work if you point it to @babel/core instead of @babel/cli, or was that just a typo? I can't test right now. [EDIT: I don't think it works for me]

@noygal
Copy link

noygal commented Nov 13, 2017

Nope my bad, can't do that with npm...

But I did investigate some farther, the issue is with this condition:
https://github.com/babel/babelify/blob/master/index.js#L65

Babel 7 remove the util object all together: #231

I wanted to try my initial approach (replacing the babel-core with @babel/core), so I comment out those lines in the code and manually copied the @babel/core folder to babel-core:

rm -rf node_modules/babel-core
cp -a node_modules/\@babel/core/. node_modules/babel-core

I'm glade to say that this hack works!

@noygal
Copy link

noygal commented Nov 14, 2017

I've open PR for this issue: #252

Meanwhile you can replace the package with my package:

"dependencies": {
    "@babel/core": "^7.0.0-beta.3",
    "@babel/preset-env": "^7.0.0-beta.32",
    "babel-core": "^6.26.0",
    "babelify": "git+https://github.com/noygal/babelify.git#feature/babel-7-support",
  }

And use the new options babel to pass your own babel package:

browserify().transform('babelify', {
  presets: ['@babel/preset-env'],
  babel: require('@babel/core')
})

@nehaleem
Copy link

nehaleem commented Dec 6, 2017

I know *lify components are prehistoric, but please.. Merge this PR #252 . We are sadly using this. Thanks

@niftylettuce
Copy link

niftylettuce commented Dec 26, 2017

Can we get this merged please? Thanks!

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

Successfully merging a pull request may close this issue.

4 participants