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

Open
DingRui12138 opened this Issue Mar 12, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@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

This comment has been minimized.

Copy link
Collaborator

babel-bot commented Mar 12, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.