kentcdodds / kentcdodds/babel-plugin-codegen

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

Open
#22 11 comments 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
347
Forks
27
PR merge metrics
No merged PRs in 30d

Description

- `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

```javascript
// 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

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with my.js and babel.config.js using the listed Node, Babel, and plugin versions. Trace the stack from node_modules/babel-plugin-codegen/dist/helpers.js:43 through replace.js and index.js, then verify the accepted module.exports form with the smallest working example. Done means the example compiles or the required syntax and a regression test are clearly identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.