GithubHelp home page GithubHelp logo

Comments (6)

selfrefactor avatar selfrefactor commented on September 21, 2024

I will give it a try, but can I ask if the project compiles without immutable?

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.

from rambda.

peachest avatar peachest commented on September 21, 2024

I will give it a try, but can I ask if the project compiles without immutable?

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 rollup-plugin-node-externals to exclude all dependencies.

The full rollup.config.js

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 index.js only container my project code without Rambda

The above issue is reproduce in this way.


extra problem

I also test not using rollup-plugin-node-externals as rollup plugins, and the output dir structure is

dist
|-- _virtual
|   `-- rambda.js
|-- node_modules
|   `-- rambda
|       |-- dist
|       |   `-- rambda.js
|       `-- immutable.js
`-- src
    `-- index.js

5 directories, 4 files

However,in this cas,execute node ./dist/src/index.js will occur

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

from rambda.

selfrefactor avatar selfrefactor commented on September 21, 2024

I spent some time exploring options of using exports object in package.json vs using main property and I found that using main is causing less trouble, so I don't think that I will change that. Still, when I have time, I will check what is the root cause for your case.

Just one question - what happens if you don't use immutable as I think this is important to know?

from rambda.

peachest avatar peachest commented on September 21, 2024

I import rambda by rambda/immutable to use readonly type declaration for typescript.
Or do you have some way to use readonly type declaration when coding and compiling without immutable

from rambda.

selfrefactor avatar selfrefactor commented on September 21, 2024

I mean, is the issue happens if you simply import rambda not rambda/immutable? This will be helpful when debugging.

from rambda.

selfrefactor avatar selfrefactor commented on September 21, 2024

I am closing this as I needed the last feedback. Feel free to reopen it with answer to it.

from rambda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.