-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Node cannot resolve rambda/immutable
import path in js file bundled by rollup+typescript
#730
Comments
I will give it a try, but can I ask if the project compiles without I will reproduce the bug and see what can it be done. I did test 9.2.0 with TS and it worked. Still, your issue helped me to find that Rambdax has issues regarding latest changes, so in any case, I want to thank you for opening it. |
Oh,I want to build my project as a lib but not app, so I use The full import path from "node:path";
import url from "node:url";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import nodeResolve from "@rollup/plugin-node-resolve";
import fs from "fs-extra";
import json5 from "json5";
import clear from "rollup-plugin-clear";
import externals from "rollup-plugin-node-externals";
import typescript from "rollup-plugin-typescript2";
const __filename = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const resolve = p => path.resolve(__dirname, p);
const packageJSONPath = resolve("package.json");
const tsconfigJSONPath = resolve("tsconfig.json");
const packageJson = json5.parse(fs.readFileSync(packageJSONPath).toString());
const tsconfigJson = json5.parse(fs.readFileSync(tsconfigJSONPath).toString());
const {
outDir: outputDirectory
} = tsconfigJson["compilerOptions"];
export default {
input: "src/index.ts",
output: {
dir: "./dist",
format: "es",
exports: "named",
preserveModules: true,
},
plugins: [
clear({
targets: ["./dist"],
}),
json(),
nodeResolve({
preferBuiltins: false,
}),
commonjs(),
typescript({
tsconfigJson,
}),
externals(),
],
}; The output structure is following dist
`-- index.js
0 directories, 1 file and the output The above issue is reproduce in this way. extra problem I also test not using dist
|-- _virtual
| `-- rambda.js
|-- node_modules
| `-- rambda
| |-- dist
| | `-- rambda.js
| `-- immutable.js
`-- src
`-- index.js
5 directories, 4 files However,in this cas,execute import { i as immutable } from '../node_modules/rambda/immutable.js';
^
SyntaxError: Named export 'i' not found. The requested module '../node_modules/rambda/immutable.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from '../node_modules/rambda/immutable.js';
const { i: immutable } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
Node.js v20.11.0 But I check the bundled rambda/immutable.js file, which is import './dist/rambda.js';
import { __exports as rambda } from '../../_virtual/rambda.js';
var immutable = rambda;
export { immutable as i }; And obviously it has exported |
I spent some time exploring options of using Just one question - what happens if you don't use |
I import rambda by |
I mean, is the issue happens if you simply import |
Describe the bug
The following code and configuration is a small demo to reproduce the real problem I met.
I am wrting TypeScript and import Rambda by path
rambda/immutable
.After bundling with Rollup, Node cannot resolve and execute the bundled file.
Context(which version of library)
version description for key package:
My package.json:
My tsconfig.json
My rollup.config.js (only key config)
My ts code
Bundled js file of Rollup
Advice
Instead of using in your package.json:
Use
exports
field:Without changing anything of code in my project, Node.js now can resolve
rambda/immutable
package correctly$ node ./dist/index.js Hello, World!
require
.The text was updated successfully, but these errors were encountered: