Skip to content

Local import as symblink in node_module not added in .dist/node_module #272

Open

Description

@MaximeLozach

Hi,

I have some import in my project that depends on local commons module shared between my different functions. I don't want to put them on public npm and don't have some kind of nexus.
I import my local common module like this :

"dependencies": {
  "database": "file:../../libs/database",
  "lambda-utils": "file:../../libs/lambda-utils",
  "s3-utils": "file:../../libs/s3-utils",
  ...
}

Until now I was with plain JS and I had no issue with serverless. My node_module seems to be well imported with the symlink of my local modules.
I now try to integrate TS, and so I added your plugin. But when I deploy, at runtime I've got error as my import to my local module can't be found.

{
    "errorType": "Error",
    "errorMessage": "Cannot find package 'database' imported from /var/task/src/functions/get-report-detail.js",
    "code": "ERR_MODULE_NOT_FOUND",
    "stack": [
        "Error [ERR_MODULE_NOT_FOUND]: Cannot find package database' imported from /var/task/src/functions/get-report-detail.js",
        "    at new NodeError (internal/errors.js:322:7)",
        "    at packageResolve (internal/modules/esm/resolve.js:732:9)",
        "    at moduleResolve (internal/modules/esm/resolve.js:773:18)",
        "    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:887:11)",
        "    at Loader.resolve (internal/modules/esm/loader.js:89:40)",
        "    at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)",
        "    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:76:40)",
        "    at link (internal/modules/esm/module_job.js:75:36)",
        "    at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:60:5)",
        "    at /var/runtime/deasync.js:23:15"
    ]
}

In S3 where the code is store for my function, I can see that .dist/node_module is missing my local module.

Activity

  1. chinanderm commented on Dec 7, 2022

    @chinanderm

    @MaximeLozach Did you ever get this resolved? I'm running into this same issue. Seems this plugin doesn't work with symlinked node_modules packages.

  2. MaximeLozach commented on Dec 7, 2022

    @MaximeLozach
    Author

    Well not really.
    We use the registry of gitlab to push our lib as artifact that get imported via npm. The mecanism is the same as public artifact so their is no problem now for us.
    But is still think my issue is a problem for project that can't for some reason, put their package on private/public repository.

  3. wernc23 commented on Jan 13, 2023

    @wernc23

    Same issue. I have a local symlinked package that is not included in the build package.

  4. chinanderm commented on Jan 13, 2023

    @chinanderm

    I ended up forking the package and using the dereference feature of fs.copySync to copy the symlinked dependencies.

    fs.copySync(
      path.resolve('node_modules'),
      path.resolve(path.join(BUILD_FOLDER, 'node_modules')),    
        {
          dereference: true,
        }
     )

    Ironically, my forked version ended up being symlinked.

  5. added a commit that references this issue on May 3, 2023
    cc33b94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions