Using this minimal repo:
// package.json
{
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"babel-plugin-macros": "^2.5.1",
"raw.macro": "^0.3.0"
}
}
// .babelrc
{
"presets": [ "@babel/preset-env" ],
"plugins": [ "babel-plugin-macros" ]
}
// src/index.js
import raw from 'raw.macro';
console.log( raw( './stuff.txt' ) );
// src/stuff.txt
Stuff Goes Here
and then compiling with simply npx babel src:
Works fine with Node v11:
$ nvm use 11
Now using node v11.15.0 (npm v6.7.0)
$ npx babel src
"use strict";
console.log("Stuff Goes Here\n");
Fails with Node v12:
$ nvm use 12
Now using node v12.1.0 (npm v6.9.0)
$ npx babel src
Error: raw.macro: Cannot find module './stuff.txt'
Require stack:
- node_modules/raw.macro/dist/raw.macro.js
- node_modules/babel-plugin-macros/dist/index.js
- node_modules/@babel/core/lib/config/files/plugins.js
- node_modules/@babel/core/lib/config/files/index.js
- node_modules/@babel/core/lib/index.js
- node_modules/@babel/cli/lib/babel/options.js
- node_modules/@babel/cli/lib/babel/index.js
- node_modules/@babel/cli/bin/babel.js
Learn more: https://www.npmjs.com/package/raw.macro
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:610:15)
at Function.resolve (internal/modules/cjs/helpers.js:21:19)
at node_modules/raw.macro/dist/raw.macro.js:1:726
at node_modules/raw.macro/dist/raw.macro.js:1:856
at Array.forEach (<anonymous>)
at node_modules/raw.macro/dist/raw.macro.js:1:145
at macroWrapper (node_modules/babel-plugin-macros/dist/index.js:44:12)
at applyMacros (node_modules/babel-plugin-macros/dist/index.js:201:14)
at ImportDeclaration (node_modules/babel-plugin-macros/dist/index.js:88:28)
at NodePath._call (node_modules/@babel/traverse/lib/path/context.js:53:20) {
code: 'MODULE_NOT_FOUND',
}
I did notice, however, that if you move the files from src into the root of the repo then it works, so it seems to be related to path resolution...
Using this minimal repo:
and then compiling with simply
npx babel src:Works fine with Node v11:
Fails with Node v12:
I did notice, however, that if you move the files from
srcinto the root of the repo then it works, so it seems to be related to path resolution...