Giter Site home page Giter Site logo

custom NODE_PATH and requires about flow HOT 17 CLOSED

facebook avatar facebook commented on May 3, 2024
custom NODE_PATH and requires

from flow.

Comments (17)

Raynos avatar Raynos commented on May 3, 2024 17

NODE_PATH is a deprecated feature.

Making flow support all possible nodejs specific hacks based on the internal interface of module seems really complicated.

from flow.

nnarhinen avatar nnarhinen commented on May 3, 2024 10

how is NODE_PATH deprecated?

And I'm happy to change my implementation to whatever else if I still can require without having do require('../../../../../../../some/path');

from flow.

dmnd avatar dmnd commented on May 3, 2024 8

I think this issue can be closed after module.system.node.resolve_dirname was added in 0.18.1.

Docs are scarce but check the .flowconfig in the test in e1e301c to see how it's used.

from flow.

kunokdev avatar kunokdev commented on May 3, 2024 7

as @dmnd mentioned; for these too lazy to search through commit changes in .flowconfig, this worked for me:

[options]
module.system.node.resolve_dirname=node_modules
module.system.node.resolve_dirname=src

from flow.

Raynos avatar Raynos commented on May 3, 2024 5

@nnarhinen

I mispoke. It was require.paths that is deprecated. NODE_PATH is a feature in node that is still supported.

However the way your using the feature is not recommended. General wisdom in the node community is that if you find yourself doing "../../../../../../../some/path" you've written a very large application and should look into breaking it out over multiple npm packages and putting more code in node_modules.

It would make sense for flow to support NODE_PATH, i.e. NODE_PATH=x flow ... if set from the cli, feature detecting for mutation of it in actual source code is a slippery slope of working on in only some cases and not all.

from flow.

Asgator avatar Asgator commented on May 3, 2024 4

@frontsideair look that. I finded decision problem
https://flow.org/en/docs/config/options/#toc-module-system-node-resolve-dirname-string

from flow.

MatrixFrog avatar MatrixFrog commented on May 3, 2024 4

@kirushi I was doing something very similar, but I discovered that actually can hide errors from you. See #5647 (comment) -- I switched to

module.name_mapper='^\(.*\)' -> '<PROJECT_ROOT>/src/\1'

from flow.

samwgoldman avatar samwgoldman commented on May 3, 2024 3

Thanks @dmnd. I think you're right that .flowconfig option will solve the problem outlined here. We have a few features here that need to be documented, and we already have tasks to add that.

from flow.

nnarhinen avatar nnarhinen commented on May 3, 2024

And it's not just nodejs specific. Browserify is the most common commonjs bundler and it supports the NODE_PATH hack too.

And I just happen to use an internal interface. If I would give NODE_PATH outside of the script, then I wouldn't have to call module internal interfaces. IMO it would seem much wiser to build on top of require (or the modules browserify uses) than to use some own implementation that clearly isn't doing at its current state a very good job (#49 for instance).

from flow.

steelbrain avatar steelbrain commented on May 3, 2024

+1 for NODE_PATH support

from flow.

vjpr avatar vjpr commented on May 3, 2024

+1

from flow.

 avatar commented on May 3, 2024

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

from flow.

frontsideair avatar frontsideair commented on May 3, 2024

I'm using nix package manager to generate the environment, which installs node packages to a folder and sets the NODE_PATH env var to that folder. We don't want to create a node_modules symlink in the working directory so we're doing all sorts of crazy hacks to make it work.

If flow can check NODE_PATH in addition to node_modules in the working directory or it could accept a command line flag for resolve_dirname, it would make our workflow much better.

from flow.

frontsideair avatar frontsideair commented on May 3, 2024

I hit this problem again, and it was weird to see my comment is the last thing on the issue. I hope this can be implemented.

from flow.

Asgator avatar Asgator commented on May 3, 2024

@frontsideair me to

from flow.

kirushi avatar kirushi commented on May 3, 2024

The settings below don't return any errors on flow (albeit there being many purposely placed errors)

.env
NODE_PATH=src/

.flowconfig
[options] module.system.node.resolve_dirname=node_modules module.system.node.resolve_dirname=src

from flow.

bogdosarov avatar bogdosarov commented on May 3, 2024

In my case works:

module.name_mapper='^\(.*\)' -> '<PROJECT_ROOT>/src/\1'
module.file_ext=.jsx
module.file_ext=.js

from flow.

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.