Cannot get past "Must module.exports a string."
See original GitHub issuebabel-plugin-codegen
version: 3.0.0node
version: 10.15.0npm
(oryarn
) version: yarn 1.13.0babel
: 7.4.5babel-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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:11 (3 by maintainers)
Top Results From Across the Web
javascript - Why can module.exports hold a String object and a ...
When I assign module. exports to a String literal object, it cannot hold any other properties and hence the error when we try...
Read more >Node Module Exports Explained - freeCodeCamp
This is a common module exports mistake that people who are starting out with Node.js often make. They assign exports to a new...
Read more >Understanding module.exports and exports in Node.js
It doesn't have to be the same as the original variable name. Variations in Syntax. I should also mention that it's possible to...
Read more >Module Methods - webpack
The require label can occur before a string. The dependency must export values with the export label. CommonJS or AMD modules cannot be...
Read more >Errors | Node.js v19.3.0 Documentation
To get the string representation of the error code, use util. ... private internal modules that are not exported cannot be imported through...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Confirming this is still an issue.
That said, it can be circumvented by invoking
codegen
directly instead of using a tagged template:here is the key codes : https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-template-literals/src/index.js#L96
after this step, the codegen function visitor dead