You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm generating variables so that my colleague who doesn't know how to code can write simple code now.
[💖this part has no problem]
// ./memeTemplate/variables.jsconstcodegen=require('codegen.macro');// preload formulas variables, and generate more variables, so my colleague can import them easilycodegen`const fs = require('fs');const formulasJSON = JSON.parse(fs.readFileSync(require.resolve('../formulas.json'), 'utf8'));const variableNames = [ ...Object.keys(formulasJSON), ...Object.keys(formulasJSON).map(name => '上期' + name), ...Object.keys(formulasJSON).map(name => '上上期' + name),];module.exports = variableNames .map( variableName => 'export var ' + variableName.replace(/[()、:()]/g, '') + ' = loader => loader.load("' + variableName + '")' ) .join(';');`;
[Here are problems]
// ./templates.js// try to automatiously import variablescodegen` 'const { ' + Object.keys(require('./memeTemplate/variables')).join(',') + '} = require("./memeTemplate/variables");'`;// using the automatiously imported variable`偿债能力分析2017年流动资产合计为${流动资产合计}`
Now it will show an error ./src/templates.js Module build failed: MacroError: The macro you imported from "undefined" is being executed outside the context of compilation with babel-plugin-macros. This indicates that you don't have the babel plugin "babel-plugin-macros" configured correctly. Please see the documentation for how to configure babel-plugin-macros properly
I had tried console.log( 'const { ' + Object.keys(require('./memeTemplate/variables')).join(',') + '} = require("./memeTemplate/variables");' );, it logs the correct require statement:
I'm generating variables so that my colleague who doesn't know how to code can write simple code now.
[💖this part has no problem]
[Here are problems]
Now it will show an error
./src/templates.js Module build failed: MacroError: The macro you imported from "undefined" is being executed outside the context of compilation with babel-plugin-macros. This indicates that you don't have the babel plugin "babel-plugin-macros" configured correctly. Please see the documentation for how to configure babel-plugin-macros properly
I had tried
console.log( 'const { ' + Object.keys(require('./memeTemplate/variables')).join(',') + '} = require("./memeTemplate/variables");' );
, it logs the correct require statement:And if I just import them statisticly:
It works correctly.
So I can't use codegen to load code generated by codegen?
Or I can't use codegen to generate import statement?
The text was updated successfully, but these errors were encountered: