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

Throw an error when I use babel-traverse to dispose some dependences. #9663

Closed
DingRui12138 opened this issue Mar 12, 2019 · 3 comments
Closed
Labels
awaiting reply i: bug i: 6.0 unsupported version outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@DingRui12138
Copy link

DingRui12138 commented Mar 12, 2019

Bug Report

babel-core\lib\transformation\file\index.js:558 throw err;
I'm coding a minipack for my project.
throw an error when I use traverse to dispose some dependences.
what's going on?
any idea. tks :)

image

babel-core\lib\transformation\file\index.js:558
TypeError: unknown: Cannot read property 'file' of undefined

This is my code

const { transformFromAst } = require('babel-core')
const babylon = require('babylon')
const traverse = require('babel-traverse').default

const translateFile2Ast = (filename) => {
  // const content = fs.readFileSync(filename, 'utf-8')

  const content = 'const a = [1,2,3];\nconsole.log([...a])'
  return babylon.parse(content, {
    sourceType: 'module'
  })
}


const translateAst2Code = (ast, code) => {
  return transformFromAst(ast, code, {
    presets: ['env', 'stage-2'],
  })
}
const ast = translateFile2Ast('test/index.js')
traverse(ast, {}) // if I don't use this line code,everything is ok,I don't know why
const code = translateAst2Code(ast, 'const a = [1,2,3];\nconsole.log([...a])')

Expected behavior/code

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

Environment

  • Babel version(s): [6.26.0 (babel-core 6.26.3)]
  • Node/npm version: [Node 8/npm 6]
  • OS: [Windows 7]
  • How you are using Babel: [node]
@babel-bot
Copy link
Collaborator

Hey @DingRui12138! 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.

@DingRui12138 DingRui12138 changed the title Throw an error when I use traverse to dispose some dependencies. Throw an error when I use traverse to dispose some dependences. Mar 13, 2019
@DingRui12138 DingRui12138 changed the title Throw an error when I use traverse to dispose some dependences. Throw an error when I use babel-traverse to dispose some dependences. Mar 13, 2019
@nicolo-ribaudo
Copy link
Member

Babel 6 isn't maintained anymore. Do you get the same error when using Babel 7?

@DingRui12138
Copy link
Author

DingRui12138 commented May 28, 2019

It works fine when I using Babel 7

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Aug 27, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Aug 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting reply i: bug i: 6.0 unsupported version outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants