Skip to content

Cannot get past "Must module.exports a string." #22

@foxbunny

Description

@foxbunny
  • babel-plugin-codegen version: 3.0.0
  • node version: 10.15.0
  • npm (or yarn) version: yarn 1.13.0
  • babel: 7.4.5
  • babel-plugin-macros: 2.5.1 (required by another dep)

Relevant code or config

// my.js
codegen`module.exports = ''`;

// babel.config.js
module.exports = {
  presets: [
    [
      '@babel/env',
      {
        targets: {
          browsers: [
            'last 2 versions',
            'ie 11',
          ]
        },
        useBuiltIns: 'usage',
        corejs: 2,
      },
    ],
  ],
  plugins: [
    'macros',
    'codegen',
    '@babel/plugin-syntax-dynamic-import',
  ],
};

What you did:

Try to compile my.js

What happened:

codegen: Must module.exports a string.

      at getReplacement (node_modules/babel-plugin-codegen/dist/helpers.js:43:11)
      at replace (node_modules/babel-plugin-codegen/dist/helpers.js:69:21)
      at asFunction (node_modules/babel-plugin-codegen/dist/replace.js:57:5)
      at asIdentifier (node_modules/babel-plugin-codegen/dist/replace.js:127:22)
      at PluginPass.Identifier (node_modules/babel-plugin-codegen/dist/index.js:37:11)
      at newFn (node_modules/@babel/traverse/lib/visitors.js:193:21)
      at NodePath._call (node_modules/@babel/traverse/lib/path/context.js:53:20)
      at NodePath.call (node_modules/@babel/traverse/lib/path/context.js:40:17)
      at NodePath.visit (node_modules/@babel/traverse/lib/path/context.js:88:12)
      at TraversalContext.visitQueue (node_modules/@babel/traverse/lib/context.js:118:16)

Reproduction repository:

Problem description:

I cannot seem to get past the Must module.exports a string. I've tried using escaped backticks, double quotes and single quotes, joining arrays, concatenating strings some other way (e.g., with + operator), etc.

What am I doing wrong?

Suggested solution:

n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions