babel-plugin-codegen icon indicating copy to clipboard operation
babel-plugin-codegen copied to clipboard

Property value expected type of string but got null

Open larsbs opened this issue 7 years ago • 2 comments

  • babel-plugin-codegen version: ^3.0.0
  • node version: 10.12.0
  • npm (or yarn) version: 6.4.1

Relevant code or config

// @codegen

const hello = 'hello';

module.exports = `
  export default {};
`;

I was expecting the simple code above to work but it just gives the error mentioned in the title.

screenshot 2018-10-26 at 17 12 46

However, if we remove the line const hello = 'hello', everything works as expected and export default {}; it's correctly generated

larsbs avatar Oct 26 '18 15:10 larsbs

Workaround:

Put everything inside a self-executing function:

// @codegen

module.exports = (() => {
  const hello = 'hello';
  return `
    export default {};
  `;
})();

Might be interesting to add this to the readme?

larsbs avatar Oct 26 '18 15:10 larsbs

Sure, thanks! Would you like to add that? Though I think it'd be better to figure out why it's not working... 🤔

kentcdodds avatar Nov 06 '18 21:11 kentcdodds